[英]JSONObject Java equivalent for Objective C
I'm working on an API for objective C which has an equivalent JAVA version. 我正在为目标C开发一个具有等效JAVA版本的API。 They used the JSON.org elements to define the JSON parsing in JAVA. 他们使用JSON.org元素在JAVA中定义JSON解析。
import org.json.JSONObject;
public class TestCodeRequest{
private HashMap<String,JSONObject> query = new HashMap<String, JSONObject>();
private JSONObject queryResult;
}
and 和
public TestCodeRequest add(String endpoint, Object... fields) {
JSONObject endpointQuery;
if ((endpointQuery = query.get(endpoint)) == null) {
endpointQuery = new JSONObject();
query.put(endpoint,endpointQuery);
}
JSONObject sq = endpointQuery;
for (int i=0;i<fields.length-2;i++) {
JSONObject tmp = sq;
if(sq.has((String)fields[i])){
try {
sq = sq.getJSONObject((String)fields[i]);
} catch(Exception e) {
throw new Semantics3Exception(
"Invalid constraint",
"Cannot add this constraint, '" + fields[i] +"' is already a value.");
}
} else {
sq = new JSONObject();
tmp.put((String)fields[i], sq);
}
}
sq.put((String)fields[fields.length-2], fields[fields.length-1]);
return this;
}
I guess NSDictionary is an objective C equivalent for HashMap. 我猜NSDictionary是HashMap的客观C等效项。 I'm using the JSONKit for JSON parsing. 我正在使用JSONKit进行JSON解析。 Wondering what would be a JSONObject in this case. 想知道在这种情况下是什么JSONObject。
JSONObject
等效于NSDictionary
(名称/值或键/值对的无序集合)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.