I would like to create a generic class which create my jsonObject.
Is it possible to create a class which can create differents kind of objects like
{"chunkSize":10,"filters"
[{"field":"segmentOwners.id","operator":"EQUAL","value":"11578","valueType":"java.lang.Integer"},
{"field":"language","operator":"EQUAL","value":"FR","valueType":"java.lang.String"},
{"field":"customerId","operator":"EQUAL","value":"77","valueType":"java.lang.Integer"}]
,"orderBy":[{"field":"creationTime","order":"DESC"}],"page":0}
OR just a simple request:
{login:"mylogin",pwd:"mypwd"}
I tried something like:
@Override
protected JSONObject doInBackground(String... params) {
byte[] result = null;
Iterator iter = mData.entrySet().iterator();
JSONObject jsonObj = new JSONObject();
Iterator it = mData.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pairs = (Map.Entry)it.next();
try {
jsonObj.put((String) pairs.getKey(), (String) pairs.getValue());
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
it.remove(); // avoids a ConcurrentModificationException
}
But i’m not sure that is the same kind of hashmap (string, jsonObjet…?)
If you want to create instances of
JSONObjectfrom JSON strings, just do the following: