本文介绍了如何更改json数据格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有特定格式的json数据,我需要更改我的代码中使用的数据格式。如何用c#代码或其他东西更改它?
我的尝试:
JSON
I have a json data in particular format,i need to change the data format to use in my code.How to change it in c# code or some other thing?
What I have tried:
JSON
[
"concepts": {
"http://dbpedia.org/resource/Chuckles_(G.I._Joe)": {
"SurfaceForms": [
{
"Score": 0.9460024,
"String": "CHUCKLES",
"Offset": 3
}
],
"Types": [ "" ],
"Support": 52
}
},
"concepts": {
"http://dbpedia.org/resource/Memory,_Sorrow,_and_Thorn": {
"SurfaceForms": [
{
"Score": 1.0,
"String": "Sithi",
"Offset": 2
}
],
"Types": [ "" ],
"Support": 43
}
}
]
在这个JSON数据中如何获得里面的分数一个SurfaceForms。
推荐答案
{
"concepts": {
"http://dbpedia.org/resource/Chuckles_(G.I._Joe)": {
"SurfaceForms": [
{
"Score": 0.9460024,
"String": "CHUCKLES",
"Offset": 3
}
],
"Types": [ "" ],
"Support": 52
}
},
"concepts": {
"http://dbpedia.org/resource/Memory,_Sorrow,_and_Thorn": {
"SurfaceForms": [
{
"Score": 1.0,
"String": "Sithi",
"Offset": 2
}
],
"Types": [ "" ],
"Support": 43
}
}
}
这里是由 []:
And here is the C# classes generated by JSON Utils: Generate C#, VB.Net, SQL Table, Java and PHP from JSON[^]:
public class SurfaceForm
{
[JsonProperty("Score")]
public double Score { get; set; }
[JsonProperty("String")]
public string String { get; set; }
[JsonProperty("Offset")]
public int Offset { get; set; }
}
public class HttpDbpediaOrgResourceMemorySorrowAndThorn
{
[JsonProperty("SurfaceForms")]
public IList<SurfaceForm> SurfaceForms { get; set; }
[JsonProperty("Types")]
public IList<string> Types { get; set; }
[JsonProperty("Support")]
public int Support { get; set; }
}
public class Concepts
{
[JsonProperty("http://dbpedia.org/resource/Memory,_Sorrow,_and_Thorn")]
public HttpDbpediaOrgResourceMemorySorrowAndThorn HttpDbpediaOrgResourceMemorySorrowAndThorn { get; set; }
}
public class Result
{
[JsonProperty("concepts")]
public Concepts Concepts { get; set; }
}
要填充类,上面的 []将向您展示如何。
To populate the classes, the above article link[^] will show you how.
这篇关于如何更改json数据格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!