Package org.json

Examples of org.json.JSONObject


    json.put("points", points);
    return json;
  }

  private JSONObject serializeMultiLineString(Geometry geometry) {
    JSONObject json = new JSONObject();

    JSONArray lineStrings = null;
    if (geometry.getGeometries() != null && geometry.getGeometries().length > 0) {
      lineStrings = new JSONArray();
      for (int i = 0; i < geometry.getGeometries().length; i++) {
        lineStrings.put(serializeLineString(geometry.getGeometries()[i]));
      }
    }
    json.put("lineStrings", lineStrings);
    putBasics(json, geometry);
    return json;
  }
View Full Code Here


    putBasics(json, geometry);
    return json;
  }

  private JSONObject serializeMultiPolygon(Geometry geometry) {
    JSONObject json = new JSONObject();
    putBasics(json, geometry);

    JSONArray polygons = null;
    if (geometry.getGeometries() != null && geometry.getGeometries().length > 0) {
      polygons = new JSONArray();
      for (int i = 0; i < geometry.getGeometries().length; i++) {
        polygons.put(serializePolygon(geometry.getGeometries()[i]));
      }
    }
    json.put("polygons", polygons);
    return json;
  }
View Full Code Here

    }
    write('}');
  }

  public void write(JSONRPCResult result) throws IOException {
    JSONObject o = new JSONObject();
    if (result.getErrorCode() == JSONRPCResult.CODE_SUCCESS) {
      o.put("id", result.getId());
      o.put("result", result.getResult());
    } else if (result.getErrorCode() == JSONRPCResult.CODE_REMOTE_EXCEPTION) {
      Throwable e = (Throwable) result.getResult();
      CharArrayWriter caw = new CharArrayWriter();
      e.printStackTrace(new PrintWriter(caw));
      JSONObject err = new JSONObject();
      err.put("code", Integer.valueOf(result.getErrorCode()));
      err.put("msg", e.getMessage());
      err.put("trace", caw.toString());
      o.put("id", result.getId());
      o.put("error", err);
    } else {
      JSONObject err = new JSONObject();
      err.put("code", Integer.valueOf(result.getErrorCode()));
      err.put("msg", result.getResult());
      o.put("id", result.getId());
      o.put("error", err);
    }
    write(o);
  }
View Full Code Here

 
  public void testJSON() throws JSONException {
    Map<String, String> map = new HashMap<String, String>();
    map.put("ru", "Privet");
    map.put("en", "Hello");
    JSONObject obj = new JSONObject(map);
    JSONObject obj2 = new JSONObject(obj.toString());
    assertEquals("Hello", obj2.getString("en"));
  }
View Full Code Here

    data = new HashMap<String, Map<String, String>>();
    if (StringUtils.isEmpty(attributes)) {
      return;
    }
    try {
      JSONObject obj = new JSONObject(attributes);
      Iterator<String> attributeIter = obj.keys();
      while (attributeIter.hasNext()) {
        String attrName = attributeIter.next();
        if (!data.containsKey(attrName)) {
          data.put(attrName, new HashMap<String, String>());
        }
        JSONObject attr = obj.getJSONObject(attrName);
        Iterator<String> langIter = attr.keys();
        while (langIter.hasNext()) {
          String language = langIter.next();
          data.get(attrName).put(language, attr.getString(language));
        }
      }
    } catch (org.json.JSONException e) {
      logger.error("Page atributes parsing problem: " + attributes);
    }
View Full Code Here

    }
    data.get(name).put(language, value);
  }
 
  public String asJSON() {
    JSONObject obj = new JSONObject(data);
    return obj.toString();
  }
View Full Code Here

    private void parseAttributes() {
    if (StringUtils.isEmpty(attributesJSON)) {
      return;
    }
    try {
      JSONObject obj = new JSONObject(attributesJSON);
      Iterator<String> attributeIter = obj.keys();
      while (attributeIter.hasNext()) {
        String attrName = attributeIter.next();
        getAttributes().put(attrName, obj.getString(attrName));
      }
    } catch (org.json.JSONException e) {
      logger.error("Config atributes parsing problem: " + attributes);
    }
    }
View Full Code Here

 
  private void parseTitle() {
    titles = new HashMap<String, String>();
    if (title != null) {
      try {
        JSONObject obj = new JSONObject(getTitleValue());
        Iterator<String> it = obj.keys();
        while (it.hasNext()) {
          String key = it.next();
          titles.put(key, obj.getString(key));
        }
      } catch (org.json.JSONException e) {
        logger.error("Page title parsing problem: " + getTitleValue());
      }
    }
View Full Code Here

    }
  }
 
  private void packTitle() {
    if (titles != null) {
      JSONObject obj = new JSONObject(titles);
      setTitleValue(obj.toString());
    }
  }
View Full Code Here

      logger.error("Config atributes parsing problem: " + attributes);
    }
    }

    private void updateAttributes() {
      attributesJSON = new JSONObject(getAttributes()).toString();
    }
View Full Code Here

TOP

Related Classes of org.json.JSONObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.