2

同等の Java バージョンを持つ Objective C の API に取り組んでいます。彼らは、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 は、HashMap に相当する客観的な C だと思います。JSON 解析にはJSONKitを使用しています。この場合、JSONObject は何になるのだろうか。

4

1 に答える 1

4

JSONObjectNSDictionary(名前/値またはキー/値のペアの順序付けられていないコレクション)と同等です。

于 2013-08-24T10:31:51.633 に答える