我正在为 Objective C 开发一个 API,它有一个等效的 JAVA 版本。 他们使用 JSON.org 元素来定义 JAVA 中的 JSON 解析。
import org.json.JSONObject;
public class TestCodeRequest{
private HashMap<String,JSONObject> query = new HashMap<String, JSONObject>();
private JSONObject queryResult;
}
和
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;
}
我猜 NSDictionary 是 C 语言中 HashMap 的等价物。我正在使用JSONKit用于 JSON 解析。想知道在这种情况下 JSONObject 是什么。
最佳答案
JSONObject
相当于 NSDictionary
(名称/值或键/值对的无序集合)。
关于java - JSONObject Java 相当于 Objective C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18417482/