我想使用JSON.net庫將C#對象序列化爲JSON。我遇到的問題是正在創建的字符串中有&的字符。JSON.net將C#對象序列化爲JSON問題
下面是通過JsonConvert.SerializeObject返回的字符串:通過JSONLint返回運行該字符串
{
"ComId": "AAAiB+AAHAALOaFAAL",
"CovId": "AAABC9AAPAAAZYUAAI",
"EffectiveDate": "\\/Date(1329368400000-0500)\\/",
"ExpirationDate": "\\/Date(1360990800000-0500)\\/",
"State": "TX",
"DeductibleAmount": 500.0,
"DeductibleType": "PD"
}
:
Parse error on line 1:
{ "ComId": &
-----^
Expecting 'STRING', '}'
下面是我試圖序列化到JSON對象:
public class CommonInfoModel
{
public virtual string ComId { get; set; }
public virtual string CovId { get; set; }
[Display(Name = "Effective Date")]
public virtual DateTime EffectiveDate { get; set; }
[Display(Name = "Expiration Date")]
public virtual DateTime ExpirationDate { get; set; }
[Display(Name = "State")]
public virtual string State { get; set; }
[Display(Name = "Deductible Amount")]
public virtual decimal DeductibleAmount { get; set; }
[Display(Name = "Deductible Type")]
public virtual string DeductibleType { get; set; }
}
我做錯了什麼?我已經搜索,似乎其他誰使用該方法得到更乾淨的字符串!提前感謝您的時間!
你爲什麼不作替換"從「然後你如何使用JSON解析它 – jcvegan 2012-02-17 15:43:39
你是從一個控制器動作返回它你試過'返回JSON(模型);?' ? – jrummell 2012-02-17 15:44:17
這是'{「ComId」:null,「CovId」:null,「EffectiveDate」:「\/Date(-62135596800000 + 0200)\ /」,「ExpirationDate」:「\/Date(-62135596800000 + 0200) \「,」State「:null,」DeductibleAmount「:0.0,」DeductibleType「:null}'當我運行**時得到的結果**'JsonConvert.SerializeObject(new CommonInfoModel())'**。與你的字符串序列化後 – 2012-02-17 15:47:46