2013-08-24 33 views
2

我正在研究具有相同JAVA版本的目標C的API。 他們使用JSON.org元素來定義JAVA中的JSON解析。目標C的JSONObject Java相當於C

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。

回答

4

JSONObject相當於NSDictionary(名稱/值或鍵/值對的無序集合)。