2
Javaのjsonの特定の属性(jsonサブセット)を抽出するためのAPI /ツールがありますか?apache-commons beanutils copyと同様ですか?例えばメインjsonの属性が少ないjsonサブセットを抽出します
私は、次のJSON
{
"fixed":[
{
"b":"some value",
"c":"some value",
"d":"some value",
"e":"some value",
"f":"some value"
},
{
"b":"value",
"c":"value",
"d":"value",
"e":"value",
"f":"value"
}
]
}
を持って、私はその正しいアプローチ
場合、私は確信して、以下の方法を思い付いた、ではなく、次のJSON{
"fixed":[
{
"b":"some value",
"e":"some value",
"f":"some value"
},
{
"b":"value",
"e":"value",
"f":"value"
}
]
}
を持っていると思います
public JSONObject parseJSON(JSONObject data,List<String> subset){
JSONArray fixedArray = (JSONArray) data.get("fixed");
JSONObject resObj = new JSONObject();
JSONArray resArray = new JSONArray();
for(int i=0;i<fixedArray.size();i++){
JSONObject element = (JSONObject) fixedArray.get(i);
JSONObject resElement = new JSONObject();
for(String s:subset){
resElement.put(s, element.get(s));
}
resArray.add(resElement);
}
return resObj.put("fixed", resArray);
}
私はthisの質問をしましたが、tには役に立たなかった彼の話題。