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

关于C#解析Json字符串
在返回的Json字符串中包含多个表,比如包含主表BILL和明细表BILLMX ,如何分别解析出BILL表存在LIST<BILL>中,将BILLMX表存入LIST<BILLMX>中??Json格式如下:
{"code":"success","msg":"success","data":{"BILL":[{"DJBH":"PA3_021002000001","SL":"5","JE":"3400"}],"BILLMX":[{"DJBH":"KA3_021001000003","SPDM":"10001","SL":"2","JE":"1000","BZ":""},{"DJBH":"KA3_021001000003","SPDM":"10002","SL":"3","JE":"2400","BZ":"Test"}]},"timer":"1333238400000"}

望高手们帮忙看看,谢谢啦。急。急。。

------解决方案--------------------
试试JSON.NET
------解决方案--------------------
public static T FromJson<T>(this string jsonText)
{
Newtonsoft.Json.JsonSerializer json = new Newtonsoft.Json.JsonSerializer();

json.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
json.ObjectCreationHandling = Newtonsoft.Json.ObjectCreationHandling.Replace;
json.MissingMemberHandling = Newtonsoft.Json.MissingMemberHandling.Ignore;
json.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;

StringReader sr = new StringReader(jsonText);
Newtonsoft.Json.JsonTextReader reader = new JsonTextReader(sr);
T result = (T)json.Deserialize(reader, typeof(T));
reader.Close();

return result;
}
要用这个插件:Newtonsoft.Json
------解决方案--------------------
Newtonsoft.Json 这个不错