我有一些json文字,我想用它来填充gridview。如果我在json数据中没有标题部分,则可以正常工作,但是如果出现错误。有人可以帮我吗,不确定我哪里出错了
读取字符串时出错。意外的令牌:StartObject。路径'[0] .headers'
ASP.NET CODE
public class Emails
{
public string status { get; set; }
public string delivered_at { get; set; }
public string sender { get; set; }
public string email_ts { get; set; }
public string email_id { get; set; }
public string host { get; set; }
public string process_status { get; set; }
public string smtpcode { get; set; }
public string recipient { get; set; }
public string response { get; set; }
public string headers { get; set; }
}
List<Emails> myDeserializedObjList = (List<Emails>)Newtonsoft.Json.JsonConvert.DeserializeObject(strResult, typeof(List<Emails>));
gvRecords.DataSource = myDeserializedObjList;
gvRecords.DataBind();
JSON VALUE
[
{
"status": "ok",
"delivered_at": "2014-02-12T20:51:48.000059+00:00",
"sender": "[email protected]",
"headers": {
"subject": "Test No 1"
},
"email_ts": "2014-02-12T20:51:46.219800+00:00",
"email_id": "1WDgmY-4gfM00-Hj",
"host": "mx1.webhost.co.nz [119.47.119.2]",
"process_status": "completed",
"smtpcode": 250,
"recipient": "[email protected]",
"response": "250 2.0.0 Ok: queued as 8022160F4F"
},
{
"status": "hardbounce",
"delivered_at": "2014-02-12T20:55:32.000047+00:00",
"sender": "[email protected]",
"headers": {
"subject": "Test No 1"
},
"email_ts": "2014-02-12T20:55:30.028400+00:00",
"email_id": "1WDgqA-4gfLik-2I",
"host": "mx1.webhost.co.nz [119.47.119.2]",
"process_status": "completed",
"smtpcode": 550,
"recipient": "[email protected]",
"response": "550 5.1.1 <[email protected]>: Recipient address rejected: User unknown in virtual mailbox table"
}
]
格式化JSON数据时出现一些错误
首先,您应使用Angel Braces [在“ header”属性之后,如下所示:
"headers":[ {
"subject": "Test No 1"
}],
第二:在模型类中,您将smtpcode定义为字符串属性,同时在JSON数据中向其传递了int值
"smtpcode": 250
它应该是 :
"smtpcode" : "250"
或者
public int smtpcode {get;set;} and keep it the same in JSON
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句