我会查看json.org的解析器。我使用 Json.NET
这是我认为您正在谈论的示例:
string json = @"{
'CPU': 'Intel',
'PSU': '500W',
'Drives': [
'DVD read/writer'
/*(broken)*/,
'500 gigabyte hard drive',
'200 gigabype hard drive'
]
}";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
while (reader.Read())
{
if (reader.Value != null)
Console.WriteLine("Token: {0}, Value: {1}", reader.TokenType, reader.Value);
else
Console.WriteLine("Token: {0}", reader.TokenType);
}
这将遍历 JSON 对象中的所有内容并输出Token
和Value
. 在这种情况下,您将得到:
Token: StartObject
Token: PropertyName, Value: CPU
Token: String, Value: Intel
Token: PropertyName, Value: PSU
Token: String, Value: 500W
Token: PropertyName, Value: Drives
Token: StartArray
Token: String, Value: DVD read/writer
Token: Comment, Value: (broken)
Token: String, Value: 500 gigabyte hard drive
Token: String, Value: 200 gigabype hard drive
Token: EndArray
Token: EndObject