访问 API 后,我得到以下 json 格式:
{
"7407": {
"survey_id": "406",
"device_id": "1",
"response_time": "2013-10-10 16:14:01",
"timezone": "0",
"language_id": "en",
"response_id": "7407",
"device_alias": "QR Code App",
"site_name": "QR Code App",
"country_name": "United States",
"state_name": "New York",
"city_name": "Suffern",
"zip": "",
"voucher_name": null,
"voucher_mode": null,
"surveyee_name": null,
"surveyee_email": null,
"surveyee_phone": null,
"ques": {
"": []
}
},
"7408": {
"survey_id": "406",
"device_id": "1",
"response_time": "2013-10-10 16:36:56",
"timezone": "0",
"language_id": "en",
"response_id": "7408",
"device_alias": "QR Code App",
"site_name": "QR Code App",
"country_name": "India",
"state_name": "Gujarat",
"city_name": "Ahmedabad",
"zip": "",
"voucher_name": null,
"voucher_mode": null,
"surveyee_name": null,
"surveyee_email": null,
"surveyee_phone": null,
"ques": {
"": []
}
} }
我JSON.Net
用来读取上面给定的 json 数据。
要将这些数据映射到 .Net 代码中,我需要 .net 中的类,其属性名称与 json 字符串中的名称相同。 但是json中有一些属性可以是动态的(在我的例子中是“7407”、“7408”等),即这个值可以根据我们传递给参数的内容来改变。
我的问题是,我们如何将 json 属性(本质上是动态的,并且可以根据提供给 api 的参数具有任何值)映射到我们的 .net 类?