如何从c#中的特殊类型json字符串中检索数据?
我尝试使用JObject从上述代码中检索数据。但它返回一个异常错误如何从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
如何从这个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,因为没有引用键。数据来自哪里?