【发布时间】:2019-03-06 20:54:36
【问题描述】:
我对 JSON 完全陌生,需要能够将我的 JSON 字符串转换为 DataTable。
这是我的 JSON。 出于安全原因,我已更改数据
[
{
"uuid": "af9fcfc7-61af-4484-aaa8-7dhcced2f2f79",
"call_start_time": 1551892096171,
"call_duration": 1150,
"created_on": "2019-03-06",
"cost": 0,
"call_type": "inbound",
"from": {
"uuid": "",
"type": "number",
"name": "",
"nickname": "",
"number": "+44 7*** ******"
},
"to": {
"uuid": "",
"type": "number",
"name": "",
"nickname": "",
"number": "+44 **** ******0"
},
"answered": true,
"answered_by": {
"uuid": "48bj949-e72e-4239-a337-e181a1b45841",
"type": "sipuser",
"name": "SipUser",
"nickname": "Myself",
"number": "1001"
},
"has_recording": true,
"call_route": "c30e45g0e-3da4-4a67-9a04-27e1d9d31129",
"is_fax": false
},
{
"uuid": "f62kmop2b-f929-4afc-8c05-a8c1bc43225d",
"call_start_time": 1551890795202,
"call_duration": 12,
"created_on": "2019-03-06",
"cost": 0.012,
"call_type": "outbound",
"from": {
"uuid": "68a50328-f5b0-4c5e-837c-667ea50878f3",
"type": "sipuser",
"name": "Spare",
"nickname": "Spare",
"number": "1011"
},
"to": {
"uuid": "",
"type": "number",
"name": "",
"nickname": "",
"number": "+44 *** *** ****"
},
"answered": true,
"answered_by": {
"uuid": "",
"type": "number",
"name": "",
"nickname": "",
"number": "+44 ***1*****0"
},
"has_recording": false,
"call_route": "",
"is_fax": false
},
{
"uuid": "b1b495c4-ecf6-44c0-8020-28c9eddc7afe",
"call_start_time": 1551890780607,
"call_duration": 10,
"created_on": "2019-03-06",
"cost": 0.012,
"call_type": "outbound",
"from": {
"uuid": "68a50328-f5b0-4c5e-837c-667ea50878f3",
"type": "sipuser",
"name": "Spare",
"nickname": "Spare",
"number": "1011"
},
"to": {
"uuid": "",
"type": "number",
"name": "",
"nickname": "",
"number": "+44 *** *** ****"
},
"answered": true,
"answered_by": {
"uuid": "",
"type": "number",
"name": "",
"nickname": "",
"number": "+44 *** *** ****"
},
"has_recording": false,
"call_route": "",
"is_fax": false
}
]
我希望它呈现的方式需要与本网站呈现数据表的方式相似
我现在一直在上网,并且开始用尽选择。我确实尝试过用类创建它,但是没有成功。 我还尝试了以下所有示例(以及其他示例)
https://www.code-sample.com/2017/04/convert-json-to-datatable-asp-net-c.html
Import Complex JSON file to C# dataTable
https://www.codeproject.com/Questions/590838/convertplusJSONplusstringplustoplusdatatable
即使这进入一个数据集,然后我从那里整理表格。任何帮助都将不胜感激。
编辑
我将解释为什么这与此处假设的重复问题有点不同
这个问题的答案似乎没有考虑到我已经嵌套了我需要访问的 JSON。我已经尝试过了,但我仍然没有得到任何 from/number 字段和 to/number 字段。 我承认我的问题是对另一个重复问题的延伸
【问题讨论】:
-
为什么您尝试的解决方案不成功?什么不起作用?
-
我尝试的一些解决方案没有包括所有列,我认为这可能是由于列标题更相似(例如 to/number 和 from/number 可能有冲突,所以我只是得到 to/number 列)。我尝试过的其他东西不断返回反序列化异常消息,对于我的生活,我无法破解(例如 Newtonsoft.Json.JsonSerializationException:'在完成反序列化对象后在 JSON 字符串中找到附加文本。路径'[0 ].uuid',第 3 行,第 11 位。')