【发布时间】:2014-04-10 17:40:49
【问题描述】:
我在 C#/aspx 中创建了这个 JSON 数组:
[
{
nome: "test",
apelido: "test"
}
]
我想像这样创建 JSON:
{
success: 1,
error: 0,
gestor: "test",
cliente: [
{
nome: "test",
apelido: "test"
}
]
}
这是我拥有的代码:
var gestor = new JArray();
foreach (System.Data.DataRow item in com.Execute("select * from utilizadores").Rows)
{
gestor.Add(new JObject(new JProperty("nome", item["first_name"].ToString()),
new JProperty("apelido", item["last_name"].ToString())));
}
context.Response.Write(gestor);
【问题讨论】:
-
这实际上不是 JSON,因为您在这个问题中拥有它。其次,我认为创建一个具有适当属性的类然后对其进行序列化比尝试像这样手动创建它要容易得多。
-
但是怎么做???你能帮忙吗?
-
在下面查看我的答案。确切地了解您正在尝试做的事情有点困难,但希望它至少可以为您指明正确的方向。
标签: c# asp.net json httphandler