Alternatively JSONArray specified field name value value

1. Ignore case JSONObject specified field names, field can still replace the corresponding value.

That is: the specified field name and field name are inconsistent capitalization output, but still can replace the value of the field names, field according to the original output after replacing

/**

* InputParam name of jsonArray in jsonobject the key, inputParam name ignoring case

To modify inputParam paramValue * corresponding to the original value, the original value into paramValue

*/

public static JSONArray replaceValue2JSONArray(JSONArray array,String inputParam,String paramValue) {
        JSONArray jsonArray = new JSONArray();
        if (array == null || array.isEmpty()) {
            return jsonArray;
        }
        
        for (int i = 0; i < array.size(); i++) {
            JSONObject jsonObject2 = array.getJSONObject(i);

            Set<String> keys = jsonObject2.keySet();
            for (String curKey : keys) {
                if (curKey.equalsIgnoreCase(inputParam)) {
                    jsonObject2.put(curKey, paramValue) ;
                }
            }
            jsonArray.add(jsonObject2);
        
        }
        
        return jsonArray;
    }

Guess you like

Origin blog.csdn.net/John_Kry/article/details/87880536