[英]Parsing a JSON dictionary that contains the same key with different casing
I have a problem;我有个问题; I would to know if there is a method to parse json file without having a unique format.我想知道是否有一种方法可以在没有唯一格式的情况下解析 json 文件。 So it may have different attributes but all of them contain the attribute Status but it can be in double.所以它可能有不同的属性,但它们都包含属性状态,但它可以是双重的。
{
"requestid": "1111",
"message": "db",
"status": "OK",
"data": [
{
"Status": "OK", // this one I would to test first to read the other attributes
"fand": "",
"nalDate": "",
"price": 1230000,
"status": 2
}
]
}
The defacto standard Json serializer for .NET is Newtonsoft.Json ( How to install ). .NET 的事实上的标准 Json 序列化程序是Newtonsoft.Json ( 如何安装)。 You can parse the Json into an object graph and work on that in any order you like:您可以将 Json 解析为对象图并按您喜欢的任何顺序进行处理:
namespace ConsoleApp3
{
using System;
using Newtonsoft.Json.Linq;
class Program
{
static void Main()
{
var text = @"{
'requestid': '1111',
'message': 'db',
'status': 'OK',
'data': [
{
'Status': 'OK', // this one I would to test first to read the other attributes
'fand': '',
'nalDate': '',
'price': 1230000,
'status': 2
}
]
}";
var json = JObject.Parse(text);
Console.WriteLine(json.SelectToken("data[0].Status").Value<string>());
Console.ReadLine();
}
}
}
With https://www.newtonsoft.com/json随着https://www.newtonsoft.com/json
Data data = JsonConvert.DeserializeObject<Data>(json);
And create the class Data with the interesting data inside the json并在 json 中使用有趣的数据创建类 Data
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.