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

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。