解析 JSON 响应的最简单方法 [英] Easiest way to parse JSON response
本文介绍了解析 JSON 响应的最简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有什么简单的方法可以解析c#下面的JSOn
Is there any easy way to parse below JSOn in c#
{"type":"text","totalprice":"0.0045","totalgsm":"1","remaincredit":"44.92293","messages": [
{"status":"1","messageid":"234011120530636881","gsm":"923122699633"}
]}
如果有多个结果.
推荐答案
请按以下步骤操作:
- 使用 json2csharp.com 将您的 JSON 转换为 C#;
- 创建一个class文件,把上面生成的代码放在里面;
- 使用 Nuget 包管理器将
Newtonsoft.Json
库添加到您的项目中; 使用以下代码转换从您的服务收到的 JSON:
- Convert your JSON to C# using json2csharp.com;
- Create a class file and put the above generated code in there;
- Add the
Newtonsoft.Json
library to your project using the Nuget Package Manager; Convert the JSON received from your service using this code:
RootObject r = JsonConvert.DeserializeObject<RootObject>(json);
(随意将 RootObject
重命名为对您更有意义的名称.其他类应保持不变.)
(Feel free to rename RootObject
to something more meaningful to you. The other classes should remain unchanged.)
这篇关于解析 JSON 响应的最简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文