2016-10-05 111 views
1

部分看起來是這樣的。反序列化JSON無效的屬性名稱

"interests": { 
    "5e0344ae18": true, 
    "545e5bdb01": true, 
    "33aa542ea0": true, 
    "f51a5f9716": true, 
    "31109a4d58": true, 
    "bf5f946fd4": true, 
    "563320981e": false 
} 

所以用於反序列化的屬性應該是我相信的。

 public Interests interests { get; set; } 
     public class Interests 
     { 
      public bool 5e0344ae18 { get; set; } 
      public bool 545e5bdb01 { get; set; } 
      public bool 33aa542ea0 { get; set; } 
      public bool f51a5f9716 { get; set; } 
      public bool 31109a4d58 { get; set; } 
      public bool bf5f946fd4 { get; set; } 
      public bool 563320981e { get; set; } 
     } 

但是由數字和字母的屬性名稱不符合每個喜歡「無效令牌'類,結構或接口成員聲明」 5e0344編譯錯誤有效。 如何屬性名在JSON數據匹配的名字嗎?

回答

0

雖然我不相信你將能夠使用以數字開頭的屬性名稱,你可能有一個字符或字符串前綴這些,做一些手工解析。

假設您正在使用C#,http://www.newtonsoft.com/json/help/html/t_newtonsoft_json_linq_jobject.htm可能允許您處理JSON響應並解析屬性而不使用自動反序列化我猜你正在使用。

這裏是另一篇文章,我發現描述了一個類似的問題和一些潛在的解決方案:Parse jsonObject when field names are unknowm

相關問題