Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从c#中的特殊类型json字符串中检索数据?_C#_Json - Fatal编程技术网

如何从c#中的特殊类型json字符串中检索数据?

如何从c#中的特殊类型json字符串中检索数据?,c#,json,C#,Json,我尝试使用JObject从上述代码中检索数据。但它返回一个异常错误 如何从这个json字符串中检索数据?请帮忙。谢谢 在项目中添加以下模型类 { query: "find a flight to go to matara to galle", topScoringIntent: { intent: "Start Activity", score: 0.999594033 }, entities: [ { entity: "sri lanka", type: "startAirport", st

我尝试使用JObject从上述代码中检索数据。但它返回一个异常错误


如何从这个json字符串中检索数据?请帮忙。谢谢

在项目中添加以下模型类

{
query: "find a flight to go to matara to galle",
topScoringIntent: {
intent: "Start Activity",
score: 0.999594033
},
entities: [
{
entity: "sri lanka",
type: "startAirport",
startIndex: 23,
endIndex: 28,
score: 0.8759165
},
{
entity: "india",
type: "endAirport",
startIndex: 33,
endIndex: 37,
score: 0.8645479
}
]
}
公共类Topscoring内容
{
公共字符串意图{get;set;}
公共双倍分数{get;set;}
}
公共类实体
{
公共字符串实体{get;set;}
公共字符串类型{get;set;}
公共int startIndex{get;set;}
公共int-endIndex{get;set;}
公共双倍分数{get;set;}
}
公共类根对象
{
公共字符串查询{get;set;}
公共TopScoringIntent TopScoringIntent{get;set;}
公共列表实体{get;set;}
}
现在

JavaScriptSerializer jss=new JavaScriptSerializer();
rootobjectobj=jss.Deserialize(jsonText);

现在,您可以作为普通的c#对象访问obj

在项目中添加以下模型类

{
query: "find a flight to go to matara to galle",
topScoringIntent: {
intent: "Start Activity",
score: 0.999594033
},
entities: [
{
entity: "sri lanka",
type: "startAirport",
startIndex: 23,
endIndex: 28,
score: 0.8759165
},
{
entity: "india",
type: "endAirport",
startIndex: 33,
endIndex: 37,
score: 0.8645479
}
]
}
公共类Topscoring内容
{
公共字符串意图{get;set;}
公共双倍分数{get;set;}
}
公共类实体
{
公共字符串实体{get;set;}
公共字符串类型{get;set;}
公共int startIndex{get;set;}
公共int-endIndex{get;set;}
公共双倍分数{get;set;}
}
公共类根对象
{
公共字符串查询{get;set;}
公共TopScoringIntent TopScoringIntent{get;set;}
公共列表实体{get;set;}
}
现在

JavaScriptSerializer jss=new JavaScriptSerializer();
rootobjectobj=jss.Deserialize(jsonText);

现在,您可以作为普通的c#对象访问obj。

使用Newtonsoft json,您也可以执行以下方法。正如我看到的,您在TopsCoringContent附近有一个嵌套的json,在entities附近有一个数组对象,所以我建议您使用JObject访问所有json数据,然后使用JArray访问数组元素并将它们添加到您的数据库中建模并返回值。请尝试一次

JavaScriptSerializer jss = new JavaScriptSerializer();
RootObject obj= jss.Deserialize<RootObject>(jsonText);

使用Newtonsoft json,您也可以执行以下方法。正如我看到的,您在topScoringIntent附近有一个嵌套的json,在entities附近有一个数组对象,因此我建议您使用JObject访问所有json数据,然后使用JArray访问数组元素,并将它们添加到您的模型中并返回值。请尝试其中一种

JavaScriptSerializer jss = new JavaScriptSerializer();
RootObject obj= jss.Deserialize<RootObject>(jsonText);

请发布您的代码。这实际上不是有效的JSON,因为没有引用键。数据来自哪里?请发布您的代码。这实际上不是有效的JSON,因为没有引用键。数据来自哪里?