如果解析Json中的某个字段的值
首先我知道可以直接利用写和 Json文件对应的字段实现直接反射,但是由于Json文件返回的字段不稳定,类无法控制这些未知字段,所以我需要override ReadJson方法,未知的字段可以用我自己的逻辑实现了,但是已知的字段无法反射成功了,囧~~
Json文件:
{
"result_ok": true,
"total_count": "4",
"page": 1,
"total_pages": 1,
"results_per_page": 50,
"data": [
{
"id": "1",
"contact_id": "",
"status": "Complete",
"is_test_data": "1",
"datesubmitted": "2011-12-09 02:07:33",
"[question(2)]": "Victor",
"[question(4), option(10001)]": "Oral Roberts",
"[question(4), option(10002)]": "",
"[question(4), option(10003)]": "Kansas St",
"[question(4), option(10004)]": "",
"[question(4), option(10005)]": "Notre Dame",
"[question(4), option(10007)]": "",
"[question(4), option(10008)]": "",
"[question(5)]": "Black pattern",
"[question(6), option(10012)]": "Logo1.gif",
"[question(6), option(10013)]": "Logo3.jpg",
"[question(6), option(10014)]": "",
"[question(6), option(10016)]": "",
"[question(8), question_pipe(\": "Man",
"[question(9), question_pipe(\": "NBA",
"[question(10), option(10024), question_pipe(\": "",
"[question(10), option(10025), question_pipe(\": "Muscle",
"[question(10), option(10026), question_pipe(\": "",
"[question(10), option(10027), question_pipe(\": "",
"[question(11)]": "",
"[question(11), question_pipe(\": "",
"[question(13)]": "20-99",
"[question(15)]": "Furniture",
"[question(16), option(10044)]": "",
"[question(17)]": "",
"[question(18), option(10053)]": "",
"[question(18), option(10054)]": "",
"[question(18), option(10056)]": "KINWAI",
"[url(\": "f299f5ef90291d40543fc731bb1fd755",
"[variable(\": "0",
"[variable(5)]": "10009",
"[variable(8)]": "",
"[variable(8), question_pipe(\": "10017",
"[variable(9)]": "",
"[variable(9), question_pipe(\": "10019",
"[variable(13)]": "10031",
"[variable(15)]": "10042",
"[variable(17)]": ""
}
]
}
我写了对应的
实体类:
[JsonObject(MemberSerialization.OptIn)]
[JsonConverter(typeof(SurveryResponseConvert