我使用C#与Newtonsoft库,我得到的错误是这样的
分析值时遇到意外字符:{. Path 'data',line 1,position 9.
这是我从call得到的结果json
var result = client.GetAsync(endpoint).Result.Content.ReadAsStringAsync().Result;
{
"data": {
"0": {
"code": "1000",
"name": "Jason",
"currency": "EUR",
"best_price": 100,
"paid": true,
"products": [
{
"name": "Music",
"price": "free",
"id": 12345
}
],
"archive_time": "08:00"
},
"1": {
"code": "2000",
"name": "James",
"currency": "EUR",
"best_price": 100,
"paid": true,
"products": [
{
"name": "Music",
"price": "free",
"id": 98521
}
],
"archive_time": null
},
"paginator": {
"total_count": 3,
"total_pages": 1,
"current_page": 1,
"per_page": 50,
"next_page_url": null,
"prev_page_url": null
},
"message": {
"message": "Success",
"status_code": 200
}
}}
这些是我的课
public class test2
{
public string data { get; set; }
public string code { get; set; }
public string name { get; set; }
public string currency { get; set; }
public double best_price { get; set; }
public string paid { get; set; }
public string archive_time { get; set; }
public _products products { get; set; }
public _paginator paginator { get; set; }
public _message message { get; set; }
}
public class _products
{
public string name { get; set; }
public string price { get; set; }
public int id { get; set; }
}
public class _paginator
{
public int total_count { get; set; }
public int total_pages { get; set; }
public int current_page { get; set; }
public int per_page { get; set; }
public bool next_page_url { get; set; }
public bool prev_page_url { get; set; }
}
public class _message
{
public string message { get; set; }
public int status_code { get; set; }
}
我的反序列化代码:
var account = JsonConvert.DeserializeObject<test2>(result.ToString());
1条答案
按热度按时间7bsow1i61#
我认为字典将有利于您的情况下,因为我怀疑你可以有更多的产品不仅仅是“和”1