解析 JSON 响应的最简单方法 [英] Easiest way to parse JSON response

查看:48
本文介绍了解析 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"}
]}

如果有多个结果.

推荐答案

请按以下步骤操作:

  1. 使用 json2csharp.com 将您的 JSON 转换为 C#;
  2. 创建一个class文件,把上面生成的代码放在里面;
  3. 使用 Nuget 包管理器将 Newtonsoft.Json 库添加到您的项目中;
  4. 使用以下代码转换从您的服务收到的 JSON:

  1. Convert your JSON to C# using json2csharp.com;
  2. Create a class file and put the above generated code in there;
  3. Add the Newtonsoft.Json library to your project using the Nuget Package Manager;
  4. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆