如何在特定索引(GSON)上更新Json数组

时间:2017-03-24 11:33:13

标签: json gson

我有包含json数组的json数据:

 {
    "dataSetId":3,
    "Viewable":null,
    "Charge":null,
    "tax":null,
    "Cards":[ //need to remove or update json array Cards here
    {
    "Id":605,
    "startCount":1,
    "endCount":500,
    "Party":0.25,
    "non-Party":0.375,
    "X-Party":1.25,
    "Y-Party":1.625
    },
    {
    "Id":605,
    "startCount":1,
    "endCount":500,
    "Party":0.28,
    "non-Party":0.377,
    "X-Party":1.26,
    "Y-Party":1.626
    }]
    }

现在,我想在上面的Json Element Cards 中插入新的json数组。我试过以下:

JsonObject orignalJson = gson.fromJson(existingJson.asString(), JsonElement.class).getAsJsonObject();
        System.out.println("orignalJson :: "+orignalJson);

    JsonObject dataElementJson = orignalJson.get("data").getAsJsonObject();
    JsonArray RateJsonArray = dataElementJson.get("Cards").getAsJsonArray();

如何在orignaljson中识别索引并更新卡片(Json数组)?

0 个答案:

没有答案