我想创建一个通用类来创建我的 jsonObject。是否可以创建一个可以创建不同类型对象的类,例如
{"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}
或者只是一个简单的请求:
{login:"mylogin",pwd:"mypwd"}
我试过类似的东西:
@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
}
但我不确定这是同一种哈希图(字符串,jsonObjet ...?)