2016-10-05 72 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

相关问题