2

i have to construct a json request with dynamic key below is the sample i need to create, i have set "dynamic_key" from a response which i get it from other service and "dynamic_value" from user interaction, i'm not sure how to change the "dynamic_key" value everytime, could someone tell me how to do it. TIA

"qty":{
   "dynamic_key":"dynamic_value"
}

2 Answers 2

2
JSONObject object = new JSONObject();
object.put("dynamic_key", "dynamic_value");
Sign up to request clarification or add additional context in comments.

2 Comments

And then toString()
Thanks, this is what i was looking for.
0

Map it is in hashmap. then get all keys from that hashmap and get values on base of that keys. For example: Map map; String is your key and object is your values. Sample Code:

Map<String, Object> map = response.getQTYData();
        List<QTY> mapList = new ArrayList<>();
        Set mapSet = map.entrySet();
        Iterator mapIterator = mapSet.iterator();
        Map.Entry mapEntry;
        while (mapIterator.hasNext()) {
            mapEntry = (Map.Entry) mapIterator.next();
            String key = (String) mapEntry.getKey();
            QTY qty = new QTY();
            qty.setKey(key);
            qty.setValue((String)map.get(key));
            mapList.add(paymentMethod);
        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.