public class Test { public int total; public int count; public OpenIdType data; public String next_openid; } public class OpenIdType { public List<string> openid; } class Program { static void Main(string[] args) { string str="{ \"total\": 2, \"count\": 2, \"data\": { \"openid\": [ \"\", \"OPENID1\", \"OPENID2\", \"OPENID3\"] }, \"next_openid\": \"NEXT_OPENID\" }"; Test test=JsonHelp.JsonDeserialize<Test>(str); } } public class JsonHelp { public static string JsonSerializer<T>(T t) { JavaScriptSerializer jsonSerialize = new JavaScriptSerializer(); return jsonSerialize.Serialize(t); } public static T JsonDeserialize<T>(string jsonString) { JavaScriptSerializer jsonSerialize = new JavaScriptSerializer(); return (T)jsonSerialize.Deserialize<T>(jsonString); } }
2 个
言简意赅,我喜欢,呵呵。
言简意赅,我也喜欢 但是转对象呢
提交错了,欸。好像是这样吧:
public class Test {
public int total;
public int count;
public OpenIdType data;
public String next_openid;
public class OpenIdType {
...
}
}
一层一层剥开来,我记得好像是类似这样的:
{
"total": 2,
"count": 2,
"data": {
"openid": [
"",
"OPENID1",
"OPENID2",
"OPENID3"
]
},
"next_openid": "NEXT_OPENID"
}
嵌套实体类。
一个实体,里面包含必要的属性外,再加一个list<entity>
设计成两个实体就可以了.
Newtonsoft.Json.dll,用这个类库