[英]Need to convert JSON to datatable
I have incoming JSON formatted like this: 我有这样输入的JSON格式:
{
"users": [
{
"radio_id": "123582",
"callsign": "ABCD",
"name": "First Last",
"city": "Dortmund",
"state": "Nordrhein-Westfalen",
"country": "Germany",
"home_rptr": "W2VL",
"remarks": "None"
},
{
"radio_id": "789456",
"callsign": "EFG",
"name": "Name Here",
"city": "Dortmund",
"state": "Nordrhein-Westfalen",
"country": "Germany",
"home_rptr": "W2VL",
"remarks": "None"
}
]
}
It is coming from a web request that I catch into a string called dataReceived. 它来自Web请求,我捕获到一个名为dataReceived的字符串中。 I then use this line of code to convert to a datatable. 然后,我使用这一行代码转换为数据表。
DataTable dtData = (DataTable)JsonConvert.DeserializeObject(dataReceived, (typeof(DataTable)));
I'm getting an error of: Unexpected JSON token when reading DataTable. 我收到以下错误:读取DataTable时出现意外的JSON令牌。 Expected StartArray, got StartObject. 应该是StartArray,得到了StartObject。 Path '', line 1, position 1. 路径'',第1行,位置1。
I suspect my problem is the data is in an array, but I'm not sure how to solve this. 我怀疑我的问题是数据在一个数组中,但是我不确定如何解决这个问题。 My objective is to have a table with each row one of the "users" objects in the json. 我的目标是在json中有一张表格,每一行都有一个“ users”对象。
Can anyone push me in the right direction? 谁能将我推向正确的方向?
var dt = JObject.Parse(json)["users"].ToObject<DataTable>();
就这些。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.