解析JSON响应的最简单方法在c#中,有什么简单的方法可以在json下面解析吗?{"type":"text","totalprice":"0.0045","totalgsm":"1","remaincredit":"44.92293","messages":
[{"status":"1","messageid":"234011120530636881","gsm":"923122699633"}]}以防出现多个结果。
3 回答
慕田峪4524236
TA贡献1875条经验 获得超5个赞
JavaScriptSerializer
var ser = new System.Web.Script.Serialization.JavaScriptSerializer();ser.DeserializeObject(json);
子衿沉夜
TA贡献1828条经验 获得超3个赞
using (var w = new WebClient()) { var json_data = string.Empty; string url = "YOUR URL"; // attempt to download JSON data as a string try { json_data = w.DownloadString(url); JavaScriptSerializer jsSerializer = new JavaScriptSerializer(); var result = jsSerializer.DeserializeObject(json_data); Dictionary<string, object> obj2 = new Dictionary<string, object>(); obj2=(Dictionary<string,object>)(result); string val=obj2["KEYNAME"].ToString(); } catch (Exception) { } // if string with JSON data is not empty, deserialize it to class and return its instance }
- 3 回答
- 0 关注
- 450 浏览
添加回答
举报
0/150
提交
取消