合并现有JSON数组中的多个JSON对象

时间:2018-03-26 11:26:16

标签: android json android-json

我有一个类似下面的jsonarray:

 [
   {
      "WarrantyGuarantee":{
         "Row Id":"RA048",
         "QuestionKey":"WarrantyGuarantee",
         "Answer":"Y"
      }
   },
   {
      "RewardLoyalty":{
         "Row Id":"RA051",
         "QuestionKey":"RewardLoyalty",
         "Answer":"Y"
      }
   },
   {
      "WarrantyGuarantee":{
         "Row Id":"RA048",
         "QuestionKey":"WarrantyGuarantee",
         "Answer":"Y"
      }
   },
   {
      "RewardLoyalty":{
         "Row Id":"RA051",
         "QuestionKey":"RewardLoyalty",
         "Answer":"Y"
      }
   },
   {
      "MinCost":{
         "Row Id":"RA044",
         "QuestionKey":"MinCost",
         "Answer":"hgf"
      }
   }
]

我也有多个json对象:

  {
   "RA048":"Y",
   "RA051":"Y"
  }

 {
   "RA049":"Y",
   "RA051":"N"
 }

我想从上面的jsonarray合并我的所有json对象。

1 个答案:

答案 0 :(得分:0)

JSONObject jo = new JSONObject();
JSONArray array = new JSONArray();
jo.put("key",(Object)array);

使用此方法。