Question

I'm working on an API for objective C which has an equivalent JAVA version. They used the JSON.org elements to define the JSON parsing in JAVA.

 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. I'm using the JSONKit for JSON parsing. Wondering what would be a JSONObject in this case.

Was it helpful?

Solution

JSONObject is equivalent to NSDictionary (an unordered collection of name/value or key/value pairs).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top