JSON.Net错误读取 [英] JSON.Net error reading
本文介绍了JSON.Net错误读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用Json.Net解析一些JSON数据.这是我的数据:
I'm trying to parse some JSON data with Json.Net. Here is my data:
[
{
"UIDClan": "1",
"UIDKnjiga": "1",
"Naslov": "Title1",
"DatumZaKada": "2013-08-09 00:00:00",
"DatumIstekRez": null,
"Spremno": "0"
},
{
"UIDClan": "1",
"UIDKnjiga": "2",
"Naslov": "Title2",
"DatumZaKada": "2013-08-08 00:00:00",
"DatumIstekRez": null,
"Spremno": "0"
},
{
"UIDClan": "1",
"UIDKnjiga": "3",
"Naslov": "Title3",
"DatumZaKada": "2013-08-09 00:00:00",
"DatumIstekRez": "2013-10-09 00:00:00",
"Spremno": "1"
}
]
使用这段代码,我想提取UIDClan数据:
With this piece of code i want to extract UIDClan data:
JObject o = JObject.Parse(s);
Console.WriteLine(o["UIDClan"]);
错误是
从JsonReader读取JObject时出错.当前JsonReader项不是对象:StartArray.路径",第1行,位置1.
Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1.
我已经使用JSONLint进行了检查,并且有效.
I've checked with JSONLint and it's valid.
我发现的示例并非以[.
The examples that I found doesn't start with [.
我做错什么了吗?
推荐答案
您可以尝试使用JArray
.
该JSON数据实际上是一个数组.
You could try using a JArray
.
This JSON data is actually an array.
JArray v = JArray.Parse(s);
获得第一项.
var firstItem = v[0]["UIDClan"].ToString();
您甚至可以使用linq
You can even use linq
var items = v.Where(x => x["UIDClan"].ToString() == "1").ToList();
这篇关于JSON.Net错误读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文