2014-10-31 131 views
1

我有一個json字符串,我想要反序列化以訪問特定成員。反序列化嵌套的json字符串導致空值

string sResponse = "{\"BALANCERESPONSE\":{\"@xmlns\":\"\",\"RESPONSECODE\":\"0\",\"RESPONSEMESSAGE\":\"Success\"}}"; 
Response conObj = new Response(); 
conObj = JsonConvert.DeserializeObject<Response>(sResponse); 

public class BALANCERESPONSE 
{ 
    public string RESPONSECODE { get; set; } 
    public string RESPONSEMESSAGE { get; set; } 
} 

public class Response 
{ 
    public BALANCERESPONSE resp_onse { get; set; } 
}   

我得到的resp_onse屬性null值。我在這裏做錯了什麼?

回答

4

您的輸入字符串沒有提及名稱,而是類型。因此,該物業不予承認,並將保持null

新:

string sResponse = "{\"resp_onse\":{\"@xmlns\":\"\",\"RESPONSECODE\":\"0\",\"RESPONSEMESSAGE\":\"Success\"}}"; 
         ^^^^^^^^^ 

老:

string sResponse = "{\"BALANCERESPONSE\":{\"@xmlns\":\"\",\"RESPONSECODE\":\"0\",\"RESPONSEMESSAGE\":\"Success\"}}"; 
         ^^^^^^^^^^^^^^^ 
相關問題