【问题标题】:JSONObject Java equivalent for Objective C目标 C 的 JSONObject Java 等效项
【发布时间】:2013-08-24 10:20:43
【问题描述】:

我正在为具有等效 JAVA 版本的目标 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 等价物。我正在使用 JSONKit 进行 JSON 解析。想知道在这种情况下什么是 JSONObject。

【问题讨论】:

    标签: java objective-c json jsonkit


    【解决方案1】:

    JSONObject 等价于 NSDictionary(名称/值或键/值对的无序集合)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-15
      • 2011-06-16
      • 2010-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多