(JSON.net) 无法反序列化当前的 JSON 数组,它来自 web-api 但这是错误的吗?
(JSON.net) cannot deserialize the current JSON array, it comes from a web-api but is it wrong?
(使用 JSON.net)
我正在尝试解析由 web-api (website) 生成的数组。这是输出:
[
{
"difficulty": 100,
"size": 8,
"kill": 1,
"name": "Refurbisher 0",
"specs": [
{
"class": "Global",
"spec": "Scholar",
"combined": false,
"data": [
{
"character_id": 138634,
"character_name": "---",
"persecondamount": 1162.87,
"ilvl": 3.4,
"duration": 369801,
"start_time": 1476819363468,
"report_code": "GP4w1NgWjVF87dYH",
"report_fight": 5,
"ranking_id": 113148996,
"guild": null,
"total": 0,
"rank": "-",
"percent": 89.939300240724,
"exploit": 0,
"banned": false,
"historical_count": 2240,
"historical_percent": 91
},
{
"character_id": 138634,
"character_name": "---",
"persecondamount": 1103.58,
"ilvl": 3.4,
"duration": 329641,
"start_time": 1477420365118,
"report_code": "qtmKzMnFx6NXy1VR",
"report_fight": 4,
"ranking_id": 118427755,
"guild": null,
"total": 0,
"rank": "-",
"percent": 86.86332696937,
"exploit": 0,
"banned": false,
"historical_count": 2601,
"historical_percent": 86
},
{
"character_id": 138634,
"character_name": "---",
"persecondamount": 775.108,
"ilvl": 3.4,
"duration": 397106,
"start_time": 1475608153904,
"report_code": "Q9rGtyaLv3fCM28K",
"report_fight": 14,
"ranking_id": 107727522,
"guild": null,
"total": 0,
"rank": "-",
"percent": 60.798351443404,
"exploit": 0,
"banned": false,
"historical_count": 1097,
"historical_percent": 71
},
{
"character_id": 138634,
"character_name": "---",
"persecondamount": 774.709,
"ilvl": 3.4,
"duration": 383086,
"start_time": 1476212953820,
"report_code": "a98jMzhDHYbmdVTt",
"report_fight": 9,
"ranking_id": 110419488,
"guild": null,
"total": 0,
"rank": "-",
"percent": 60.757687862686,
"exploit": 0,
"banned": false,
"historical_count": 1762,
"historical_percent": 67
},
{
"character_id": 138634,
"character_name": "---",
"persecondamount": 571.689,
"ilvl": 3.4,
"duration": 455377,
"start_time": 1475086407115,
"report_code": "XbFYWyL1gDJ9pB4Q",
"report_fight": 3,
"ranking_id": 106604925,
"guild": null,
"total": 0,
"rank": "-",
"percent": 39.931594034917,
"exploit": 0,
"banned": false,
"historical_count": 209,
"historical_percent": 43
}
],
"best_persecondamount": 1162.87,
"best_duration": 329641,
"best_historical_percent": 91,
"best_allstar_points": 102.78152640182,
"best_combined_allstar_points": 0,
"possible_allstar_points": 120,
"historical_total": 5,
"historical_median": 71,
"historical_avg": 71.6
}
],
"variable": false,
"partition": 1
}
]
但我不断收到此错误:Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'WindowsApplication1.FFLogs' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
目前正在使用这段代码(将json替换为上面的代码):
Dim obj = JsonConvert.DeserializeObject(Of FFLogs)(json)
MessageBox.Show(obj.name)
我的类:
Public Class Datum
Public Property character_id As Integer
Public Property character_name As String
Public Property persecondamount As Double
Public Property ilvl As Double
Public Property duration As Integer
Public Property start_time As Object
Public Property report_code As String
Public Property report_fight As Integer
Public Property ranking_id As Integer
Public Property guild As Object
Public Property total As Integer
Public Property rank As String
Public Property percent As Double
Public Property exploit As Integer
Public Property banned As Boolean
Public Property historical_count As Integer
Public Property historical_percent As Integer
End Class
Public Class Spec
Public Property spec As String
Public Property combined As Boolean
Public Property data As Datum()
Public Property best_persecondamount As Double
Public Property best_duration As Integer
Public Property best_historical_percent As Integer
Public Property best_allstar_points As Double
Public Property best_combined_allstar_points As Integer
Public Property possible_allstar_points As Integer
Public Property historical_total As Integer
Public Property historical_median As Double
Public Property historical_avg As Double
End Class
Public Class FFLogs
Public Property difficulty As Integer
Public Property size As Integer
Public Property kill As Integer
Public Property name As String
Public Property specs As Spec()
Public Property variable As Boolean
Public Property partition As Integer
End Class
关于如何完成这项工作的任何提示?我不知道我是否必须使用另一种反序列化方式,因为输出很奇怪或 smth,尝试使输出也成为一个衬里,看看是否有帮助。
尝试将您的代码更改为:
Dim obj = JsonConvert.DeserializeObject(Of List(Of FFLogs))(json)
MessageBox.Show(obj.name)
(使用 JSON.net) 我正在尝试解析由 web-api (website) 生成的数组。这是输出:
[
{
"difficulty": 100,
"size": 8,
"kill": 1,
"name": "Refurbisher 0",
"specs": [
{
"class": "Global",
"spec": "Scholar",
"combined": false,
"data": [
{
"character_id": 138634,
"character_name": "---",
"persecondamount": 1162.87,
"ilvl": 3.4,
"duration": 369801,
"start_time": 1476819363468,
"report_code": "GP4w1NgWjVF87dYH",
"report_fight": 5,
"ranking_id": 113148996,
"guild": null,
"total": 0,
"rank": "-",
"percent": 89.939300240724,
"exploit": 0,
"banned": false,
"historical_count": 2240,
"historical_percent": 91
},
{
"character_id": 138634,
"character_name": "---",
"persecondamount": 1103.58,
"ilvl": 3.4,
"duration": 329641,
"start_time": 1477420365118,
"report_code": "qtmKzMnFx6NXy1VR",
"report_fight": 4,
"ranking_id": 118427755,
"guild": null,
"total": 0,
"rank": "-",
"percent": 86.86332696937,
"exploit": 0,
"banned": false,
"historical_count": 2601,
"historical_percent": 86
},
{
"character_id": 138634,
"character_name": "---",
"persecondamount": 775.108,
"ilvl": 3.4,
"duration": 397106,
"start_time": 1475608153904,
"report_code": "Q9rGtyaLv3fCM28K",
"report_fight": 14,
"ranking_id": 107727522,
"guild": null,
"total": 0,
"rank": "-",
"percent": 60.798351443404,
"exploit": 0,
"banned": false,
"historical_count": 1097,
"historical_percent": 71
},
{
"character_id": 138634,
"character_name": "---",
"persecondamount": 774.709,
"ilvl": 3.4,
"duration": 383086,
"start_time": 1476212953820,
"report_code": "a98jMzhDHYbmdVTt",
"report_fight": 9,
"ranking_id": 110419488,
"guild": null,
"total": 0,
"rank": "-",
"percent": 60.757687862686,
"exploit": 0,
"banned": false,
"historical_count": 1762,
"historical_percent": 67
},
{
"character_id": 138634,
"character_name": "---",
"persecondamount": 571.689,
"ilvl": 3.4,
"duration": 455377,
"start_time": 1475086407115,
"report_code": "XbFYWyL1gDJ9pB4Q",
"report_fight": 3,
"ranking_id": 106604925,
"guild": null,
"total": 0,
"rank": "-",
"percent": 39.931594034917,
"exploit": 0,
"banned": false,
"historical_count": 209,
"historical_percent": 43
}
],
"best_persecondamount": 1162.87,
"best_duration": 329641,
"best_historical_percent": 91,
"best_allstar_points": 102.78152640182,
"best_combined_allstar_points": 0,
"possible_allstar_points": 120,
"historical_total": 5,
"historical_median": 71,
"historical_avg": 71.6
}
],
"variable": false,
"partition": 1
}
]
但我不断收到此错误:Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'WindowsApplication1.FFLogs' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
目前正在使用这段代码(将json替换为上面的代码):
Dim obj = JsonConvert.DeserializeObject(Of FFLogs)(json)
MessageBox.Show(obj.name)
我的类:
Public Class Datum
Public Property character_id As Integer
Public Property character_name As String
Public Property persecondamount As Double
Public Property ilvl As Double
Public Property duration As Integer
Public Property start_time As Object
Public Property report_code As String
Public Property report_fight As Integer
Public Property ranking_id As Integer
Public Property guild As Object
Public Property total As Integer
Public Property rank As String
Public Property percent As Double
Public Property exploit As Integer
Public Property banned As Boolean
Public Property historical_count As Integer
Public Property historical_percent As Integer
End Class
Public Class Spec
Public Property spec As String
Public Property combined As Boolean
Public Property data As Datum()
Public Property best_persecondamount As Double
Public Property best_duration As Integer
Public Property best_historical_percent As Integer
Public Property best_allstar_points As Double
Public Property best_combined_allstar_points As Integer
Public Property possible_allstar_points As Integer
Public Property historical_total As Integer
Public Property historical_median As Double
Public Property historical_avg As Double
End Class
Public Class FFLogs
Public Property difficulty As Integer
Public Property size As Integer
Public Property kill As Integer
Public Property name As String
Public Property specs As Spec()
Public Property variable As Boolean
Public Property partition As Integer
End Class
关于如何完成这项工作的任何提示?我不知道我是否必须使用另一种反序列化方式,因为输出很奇怪或 smth,尝试使输出也成为一个衬里,看看是否有帮助。
尝试将您的代码更改为:
Dim obj = JsonConvert.DeserializeObject(Of List(Of FFLogs))(json)
MessageBox.Show(obj.name)