Java 如果Json对象中有重复的键,如何将Json对象映射到pojo

Java 如果Json对象中有重复的键,如何将Json对象映射到pojo,java,json,javabeans,pojo,jsonschema2pojo,Java,Json,Javabeans,Pojo,Jsonschema2pojo,下面是JSON对象的示例 { "primaryAccountNumber":"4353453", "processingCode":"3453", "transactionAmount":"34534", "transmissionDateTime":"34534", "receiptsFields":{ "line":"BHN VALIDATION - DAR", "line":"Phone", "line":":Amo

下面是JSON对象的示例

{  
   "primaryAccountNumber":"4353453",
   "processingCode":"3453",
   "transactionAmount":"34534",
   "transmissionDateTime":"34534",
   "receiptsFields":{  
      "line":"BHN VALIDATION - DAR",
      "line":"Phone",
      "line":":Amount: 25.00",
      "line":"BHN Order ID: 9GMAQH0",
      "line":"ALL SALES FINAL",
      "line":"Terms and Conditions",
      "line":"Store ID: 06220",
      "line":"redemptionAccountNumber",
      "line":"",
      "line":"",
      "line":"",
      "line":"",
      "line":"",
      "line":"",
      "line":"",
      "line":"",
      "line":":"
   },
   "termsAndConditions":"Terms and Conditions of the card will be displayed in this area. The maximum characters allowed are nine hundred and ninety nine (999)."
}

POJO中要映射的接收字段类型是什么?例如,transmissionDateTime我们有字符串。相同的receiptsFields的“建议我”类型,以便响应将自动映射到pojo

类型的名称无关紧要,只要它具有正确的属性即可。就你的情况来说

public class ReceiptField{
    public String line;
}
然而,我不认为这个JSON能达到您想要的效果。 在receiptsFields属性中,所有属性都命名为line,因此只考虑最后一个属性(在您的示例中为“:”。数组似乎更适合这里

编辑:要回答您的评论,您是否可以控制输入JSON? 如果是这样的话:

 {
  "primaryAccountNumber": "4353453",
  "processingCode": "3453",
  "transactionAmount": "34534",
  "transmissionDateTime": "34534",
  "receiptsFields": [
    "BHN VALIDATION - DAR",
    "Phone",
    ":Amount: 25.00",
    "BHN Order ID: 9GMAQH0",
    "ALL SALES FINAL",
    "Terms and Conditions",
    "Store ID: 06220",
    "redemptionAccountNumber",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    ":"
  ],
  "termsAndConditions": "Terms and Conditions of the card will be displayed in this area. The maximum characters allowed are nine hundred and ninety nine (999)."
}

这将是一个目标。。。您还可以使用下面的链接将json转换为pojo,使用对象its not WORKING您是对的。现在我得到的是“:”只。你能给我举个数组的例子吗?就像我们如何处理我的编辑一样,它假定要更改JSON输入。不,我不能控制JSON输入。输入JSON将与此相同。我们无法更改输入字符串。那么,如果您需要receiptFields中的所有信息,恐怕您除了手动解析之外别无选择,因为正如@Jaboy所提到的,非唯一属性名不应该出现。我的建议是执行字符串操作,将输入JSON转换为我建议的内容,然后将其解析为对象。