日期:2014-05-17  浏览次数:20469 次

请问如何使用Newtonsoft.Json生成这样的json字符串
JScript code

[
{ "娱乐热门": [{ "name": "房间名", "id": 1 },{ "name": "房间名", "id": 1 } ] },
{ "游戏热门": [{ "name": "房间名", "id": 1 },{ "name": "房间名", "id": 1 } ] }, 
{ "特色推荐": [{ "name": "房间名", "id": 1 },{ "name": "房间名", "id": 1 } ] }
]



初学json 请大家帮助下

------解决方案--------------------
用一个对象列表
public class Category
{
Name {get;set;}
IList<Room> Rooms {get;set;}
}

public class Room
{
Name {get;set}
ID {get;set;}
}

给IList<Category>赋值,再用Newtonsoft.Json来生成就行了
------解决方案--------------------
javascriptserializer此了可完成此功能,没必要用外挂:
http://msdn.microsoft.com/zh-cn/library/system.web.script.serialization.javascriptserializer.aspx
------解决方案--------------------
探讨

引用:

用一个对象列表
public class Category
{
Name {get;set;}
IList<Room> Rooms {get;set;}
}

public class Room
{
Name {get;set}
ID {get;set;}
}

给IList<Category>赋值,再用Newtonsoft.Js……
……

------解决方案--------------------
探讨
用一个对象列表
public class Category
{
Name {get;set;}
IList<Room> Rooms {get;set;}
}

public class Room
{
Name {get;set}
ID {get;set;}
}

给IList<Category>赋值,再用Newtonsoft.Json来生成就行了