Package org.json.simple.parser

Examples of org.json.simple.parser.JSONParser


     *
     * @return a {@code JSONParser} instance
     */
    protected synchronized JSONParser getJSONParser() {
        if (parser == null) {
            parser = new JSONParser();
        }
        return parser;
    }
View Full Code Here


     * @param json string to be parsed
     * @return a {@code JSONObject}
     * @throws {@code AssertionError} if the string cannot be parsed into a {@code JSONObject}
     */
    protected JSONObject parseJSONObject(String json) throws AssertionError {
        JSONParser parser = getJSONParser();
        try {
            Object obj = parser.parse(json);
            assertTrue(obj instanceof JSONObject);
            return (JSONObject) obj;
        } catch (Exception e) {
            throw new AssertionError("not a valid JSON object: " + e.getMessage());
        }
View Full Code Here

     * @param json string to be parsed
     * @return a {@code JSONArray}
     * @throws {@code AssertionError} if the string cannot be parsed into a {@code JSONArray}
     */
    protected JSONArray parseJSONArray(String json) throws AssertionError {
        JSONParser parser = getJSONParser();
        try {
            Object obj = parser.parse(json);
            assertTrue(obj instanceof JSONArray);
            return (JSONArray) obj;
        } catch (Exception e) {
            throw new AssertionError("not a valid JSON array: " + e.getMessage());
        }
View Full Code Here

     */
    @SuppressWarnings("unchecked")
    protected Map<String, Object> parseJsonString(String jsonString) throws ParseException {

        /*parse the json object */
        JSONParser parser = new JSONParser();
        JSONObject obj = (JSONObject) parser.parse(jsonString);

        Set<Entry<String, Object>> entries = obj.entrySet();
        for (Entry<String, Object> entry : entries) {

            String key = entry.getKey();
View Full Code Here

   *
   * @throws IOException thrown if the <code>InputStream</code> could not be JSON parsed.
   */
  private static Object jsonParse(HttpURLConnection conn) throws IOException {
    try {
      JSONParser parser = new JSONParser();
      return parser.parse(new InputStreamReader(conn.getInputStream()));
    } catch (ParseException ex) {
      throw new IOException("JSON parser error, " + ex.getMessage(), ex);
    }
  }
View Full Code Here

    public SimpyIoSocket(String addr) throws Exception {
        final String[] parts = addr.split(":");
        final String host = parts[0];
        final int port = Integer.parseInt(parts[1]);
        this.sock = new Socket(host, port);
        this.parser = new JSONParser();
        this.outMsgId = 0;

        this.header = ByteBuffer.allocate(4);
        this.header.order(ByteOrder.BIG_ENDIAN);
        this.input = new BufferedInputStream(this.sock.getInputStream());
View Full Code Here

        RestResponse response = request(path, GET, params);
        if (response.isError()) throw new IOException(response.getResponseText());

        if (response.isJson()) {
            try {
                return (JSONArray) new JSONParser().parse(response.getResponseText());
            } catch (org.json.simple.parser.ParseException e) {
                throw new IOException(e);
            }
        } else {
            throw new IOException("Response is not a JSON format.");
View Full Code Here

        RestResponse response = request(path, GET);
        if (response.isError()) throw new IOException(response.getResponseText());

        if (response.isJson()) {
            try {
                return (JSONObject) new JSONParser().parse(response.getResponseText());
            } catch (org.json.simple.parser.ParseException e) {
                throw new IOException(e);
            }
        } else {
            throw new IOException("Response is not a JSON format.");
View Full Code Here

            response = request(location, GET);
            if (response.isError()) throw new IOException(response.getResponseText());

            if (response.isJson()) {
                try {
                    return (JSONObject) new JSONParser().parse(response.getResponseText());
                } catch (org.json.simple.parser.ParseException e) {
                    throw new IOException(e);
                }
            } else {
                throw new IOException("Response is not a JSON format.");
View Full Code Here

  public static void extractMetricsFromJmxJson(InputStream jmxStream, String jmxUrl,
                                               Map<String, String> jmxProperties,
                                               Map<String, Metric> metrics)
      throws IOException, ParseException {
    JSONParser parser = new JSONParser();
    Object obj = parser.parse(IOUtils.toString(jmxStream));
    JSONObject jsonObject = (JSONObject) obj;
    for (String key : metrics.keySet()) {
      Metric metric = metrics.get(key);
      String jsonKey = extractJsonKeySingleLevel(metric.getMetric());
      Object value = jsonObject.get(jsonKey);
View Full Code Here

TOP

Related Classes of org.json.simple.parser.JSONParser

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.