简体   繁体   English

JSON 解析器不返回数字

[英]JSON parser not returning numbers

I have the following JSON structure:我有以下 JSON 结构:

{
   "status": "Completed",
   "notes": null,
   "members":    {
      "0":       {
         "year": "2",
         "details":          {
            "id": "14899975",
            "anotherId": "11013306"
         },
         "aName": "Fred",
         "amounts":          {
            "First": 589.48,
            "Second": 1000,
            "Third": 339.48
         }
      },
      "1":       {
         "year": "2",
         "details":          {
            "id": "14899976",
            "anotherId": "11013306"
         },
         "aName": "George",
         "amounts":          {
            "First": 222.22,
            "Second": 2000,
            "Third": 22.22
         }
      },
      "2":       {
         "year": 1,
         "details":          {
            "id": "14899976",
            "anotherId": "11013306"
         },
         "aName": "Albert",
         "amounts":          {
            "First": 333.33,
            "Second": 3000,
            "Third": 33.33
         },
      }
   }
}

I am using Spring RESTTemplate and JacksonMapping2HttpMessageConverter, and the following structures to receive the result of parsing the above JSON structure:我正在使用 Spring RESTTemplate 和 JacksonMapping2HttpMessageConverter,以及以下结构来接收解析上述 JSON 结构的结果:

@JsonIgnoreProperties(ignoreUnknown = true)
public class Response {
  private String            status;
  private String            notes;
  private Map<String,Struct1>   quotes;
}

@JsonIgnoreProperties(ignoreUnknown = true)
 class Struct1 {
    private int         year;
    private Struct2     details;
    private String          aName;
    private Struct3     amounts;
}

@JsonIgnoreProperties(ignoreUnknown = true)
 class Struct2 {
    private String id;
    private String anotherId;
}

@JsonIgnoreProperties(ignoreUnknown = true)
 class Struct3 {
    private float First;
    private float Second;
    private float Third;
 }

All of these also have appropriate setters and getters for all fields.所有这些也有适用于所有字段的适当的 setter 和 getter。

My problem is that the number values in Struct3 are not filled in. I've tried making them float, Float, String, and BigDecimal, and the result is either null or 0.0.我的问题是 Struct3 中的数字值没有填充。我尝试将它们设置为 float、Float、String 和 BigDecimal,结果为 null 或 0.0。

I've tried putting a breakpoint in the setter for the first field, hoping我试过在第一个字段的 setter 中放置一个断点,希望

What am I missing?我错过了什么? Can the capital letters in the JSON be causing a problem, do I need alternate field names? JSON 中的大写字母是否会导致问题,我是否需要备用字段名称?

It turned out to be the capital letters at the beginning of the field names;原来是字段名开头的大写字母; I added annotations like @JsonProperty("First") on the line before the getter of the field, and renamed the field to first , and now it's working.我在字段的 getter 之前的行上添加了@JsonProperty("First")类的注释,并将该字段重命名为first ,现在它可以工作了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM