wp8 json2csharp


string jsonData = "{\"result\":\"600\",\"data\":{\"items\":[{\"no\":\"111\",\"uid\":\"3333333\"},{\"no\":\"2222\",\"uid\":\"44444444\"}]},\"head\":{\"server\":\"api.baidu.cn\"}}";

JObject jsonObj = JObject.Parse(jsonData);
string name = jsonObj["result"].ToString();
string province = ((JObject)jsonObj["head"])["server"].ToString();

var jo = JObject.Parse(jsonData)["data"];
if (jo.ToString() == "")
new SearchLoveModel();

Data list = new Data();
Item status = null;
var jItems = jo["items"];
if (jItems != null)
{
foreach (var j in jItems.Children())
{
status = j.ToObject<Item>();

if (!string.IsNullOrEmpty(status.No))
{
status.No = "序号" + status.No;
}
if (!string.IsNullOrEmpty(status.UId))
{
status.UId = "账号" + status.UId;
}
list.items.Add(status);
}
}

 

第二种方法

SearchLoveModel info = new SearchLoveModel();
using(MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(json)))
{
DataContractJsonSerializer ser = new DataContractJsonSerializer(info.GetType());
info = ser.ReadObject(ms) as SearchLoveModel;
}

 

model

[DataContract]
public class Head
{
[DataMember]
public string server { get; set; }
}
[DataContract]
public class Item
{
[DataMember]
public string no { get; set; }
[DataMember]
public string uid { get; set; }
}
[DataContract]
public class Data
{
public Data()
{
items = new List<Item>();
}
[DataMember]
public List<Item> items { get; set; }
}
[DataContract]
public class SearchLoveModel
{
[DataMember]
public string result { get; set; }
[DataMember]
public Head head { get; set; }
[DataMember]
public Data data { get; set; }
}

http://json2csharp.com/#

http://www.cnblogs.com/pen-ink/archive/2011/10/06/2199715.html

http://www.cnblogs.com/huizhang212/p/MetroJson.html

http://wenwen.soso.com/z/q181676143.htm

wp8 json2csharp

上一篇:javascript Date format(js日期格式化)


下一篇:在linux下搭建NFS服务器实现文件共享