问题遇到的现象和发生背景
JSON格式 序列化 同一键value 有多种结构
同一JSON
{
"control":"Text",
"id":"Text-1655881336941",
"value":{
"text":"上海厂"
}
},
{
"control":"Table",
"id":"Table-1655881344947",
"value":{
"children":[
{
"list":[
{
"control":"Text",
"id":"Text-1655881359205",
"title":[
Object{...}
],
"value":{
"text":"0001"
}
},
{
"control":"Text",
"id":"Text-1655881380477",
"title":[
{
"text":"品号",
"lang":"zh_CN"
}
],
"value":{
"text":"210200180"
}
},
问题相关代码,请勿粘贴截图
/*
Value vl = new Value
{
text = "董事长"
};
*/
List<ContentsItem> contentsItem = new List<ContentsItem>();
/*
ContentsItem contentsItem1 = new ContentsItem
{
control = "Text",
id = "Text-1655881133362",
value= vl
};
*/
//contentsItem.Add(contentsItem1);
//单身
List<TitleItem> titleItem = new List<TitleItem>();
TitleItem s_titleItem = new TitleItem
{
text = "aege",
lang = "zh_CN"
};
//titleItem.Add(s_titleItem);
titleItem.Add(new TitleItem(){ text = "aege", lang = "zh_CN" });
List<ListItem> listItem = new List<ListItem>();
ListItem s_listItem = new ListItem
{
control ="",
id="",
title= titleItem,//new list<TitleItem>() { text = "aege", lang = "zh_CN" },
value =new Value() { text = "asgasdg" }
};
listItem.Add(s_listItem);
List<ChildrenItem> childrenItem = new List<ChildrenItem>();
ChildrenItem s_Item = new ChildrenItem
{
list= listItem
};
childrenItem.Add(s_Item);
Value tRoot = new Value()
{
children= childrenItem
};
string tjson = JsonConvert.SerializeObject(tRoot);
//单头
contentsItem.Add(new ContentsItem() { control = "Text", id = "Text-1655881133362", value=(new Value() {text= "董事长" }) });
contentsItem.Add(new ContentsItem() { control = "Text", id = "Text-1655881133999", value = (new Value() { text = "总经理" }) });
contentsItem.Add(new ContentsItem() { control = "Table", id = "Table-1655881344947", value = tRoot });
Apply_data app_Data = new Apply_data //(new Value() { text = tRoot.ToString() })
{
contents= contentsItem
};
List<Summary_infoItem> s_info = new List<Summary_infoItem>();
/*
Summary_infoItem summary_infoItem = new Summary_infoItem
{
text = "x",
lang = "zh_CN"
};
*/
//s_info.Add(summary_infoItem);
s_info.Add(new Summary_infoItem() { text = "第一行备注", lang = "zh_CN" });
List<Summary_list> s_list = new List<Summary_list>();
Summary_list summary_list = new Summary_list
{
summary_info= s_info
};
s_list.Add(summary_list);
Root myRoot = new Root
{
creator_userid = "100001",
template_id = "ZvdPvqY3CBa4YXg64VwB32wQTgwUtFcWNpZH1i",
use_template_approver = 1,
apply_data= app_Data,
summary_list = s_list
};
string json = JsonConvert.SerializeObject(myRoot);
textBox1.Text = json;
public class ContentsItem
{
public string control { get; set; }
public string id { get; set; }
public Value value { get; set; }
}
public class ListItem
{
///
///
///
public string control { get; set; }
///
///
///
public string id { get; set; }
///
///
///
public List<TitleItem> title { get; set; }
///
///
///
public Value value { get; set; }
}
运行结果及报错内容
无法实现格式
我的解答思路和尝试过的方法
没有想到
我想要达到的结果
对像JSON序列化