이 json을 정확하게 만들어야합니다. 문자열 조작을 사용할 수 있지만 클래스를 사용하여 만들고 싶습니다.
{
"articles":{
"3":{
"id":"3",
"label":"Preambolo",
"leaf":true,
"pathArray":[
{
"id":"1",
"label":"TITOLO I Disposizioni Generali"
},
{
"id":"2",
"label":"Capo I Definizioni e classificazioni generali"
}
],
"path":"TITOLO I Disposizioni Generali::Capo I Definizioni e classificazioni generali"
}
}
}
이것은 내 코드입니다.
public class PathArrayItem {
public string id {
get;
set;
}
public string label {
get;
set;
}
public PathArrayItem(string id, string label) {
this.id = id;
this.label = label;
}
}
public class item {
public string id {
get;
set;
}
public string label {
get;
set;
}
public bool leaf {
get;
set;
}
public List < PathArrayItem > pathArray {
get;
set;
}
public string path {
get;
set;
}
}
void test() {
List < item > art = new List < item > ();
item item_3 = new item();
item_3.id = "3";
item_3.label = "Preambolo";
item_3.leaf = true;
item_3.pathArray = new List < PathArrayItem > ();
item_3.pathArray.Add(new PathArrayItem("1", "TITOLO I Disposizioni Generali"));
item_3.pathArray.Add(new PathArrayItem("2", "Capo I Definizioni e classificazioni generali"));
item_3.path = "TITOLO I Disposizioni Generali::Capo I Definizioni e classificazioni generali";
art.Add(item_3);
txtOutput.Text = Newtonsoft.Json.JsonConvert.SerializeObject(new {
articles = art
});
}
이것은 내 코드가 생성하는 출력입니다.
{
"articles":[
{
"id":"3",
"label":"Preambolo",
"leaf":true,
"pathArray":[
{
"id":"1",
"label":"TITOLO I Disposizioni Generali"
},
{
"id":"2",
"label":"Capo I Definizioni e classificazioni generali"
}
],
"path":"TITOLO I Disposizioni Generali::Capo I Definizioni e classificazioni generali"
}
]
}
변경해야 할 사항 :
사용하는 대신 List<item>
사용할 수 있습니다Dictionary<int, item>
Dictionary<int, item> art = new Dictionary<int, item>();
item item_3 = new item();
item_3.id = "3";
item_3.label = "Preambolo";
item_3.leaf = true;
item_3.pathArray = new List<PathArrayItem>();
item_3.pathArray.Add(new PathArrayItem("1", "TITOLO I Disposizioni Generali"));
item_3.pathArray.Add(new PathArrayItem("2", "Capo I Definizioni e classificazioni generali"));
item_3.path = "TITOLO I Disposizioni Generali::Capo I Definizioni e classificazioni generali";
art.Add(3, item_3);
당신에게 줄 것입니다
{"articles":{"3":{"id":"3","label":"Preambolo","leaf":true,"pathArray":[{"id":"1","label":"TITOLO I Disposizioni Generali"},{"id":"2","label":"Capo I Definizioni e classificazioni generali"}],"path":"TITOLO I Disposizioni Generali::Capo I Definizioni e classificazioni generali"}}}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다