Package org.json

Examples of org.json.JSONObject


      if (statusCode!=HttpStatus. SC_OK)
        throw new ClientError("HTTP Status - " +
          HttpStatus.getStatusText(statusCode) + " (" + statusCode + ")");
      JSONTokener tokener= new JSONTokener(postMethod.getResponseBodyAsString());
      Object rawResponseMessage= tokener.nextValue();
      JSONObject responseMessage= (JSONObject)rawResponseMessage;
      if (responseMessage==null)
        throw new ClientError("Invalid response type - " + rawResponseMessage.getClass());
      return responseMessage;   
    } catch (ParseException e) {
      throw new ClientError(e);
View Full Code Here


        } else if (methodName.equals("equals")) {
            return (proxyObj == args[0] ? Boolean.TRUE : Boolean.FALSE);
        } else if (methodName.equals("toString")) {
            return proxyObj.getClass().getName() + '@' + Integer.toHexString(proxyObj.hashCode());
        }
    JSONObject message= new JSONObject();
    String tag= proxyMap.get(proxyObj);
    String methodTag= tag==null ? "" : tag + ".";
    methodTag+=methodName;
    message.put("method", methodTag);

    JSONArray params= new JSONArray();
    if (args!=null) {
      for(Object arg: args) {
        SerializerState state= new SerializerState();
        params.put(message2Object.marshall(state, arg));
      }
    }
    message.put("params", params);
    message.put("id", 1);
    JSONObject responseMessage= session.sendAndReceive(message);
    if (!responseMessage.has("result"))
      processException(responseMessage);
    Object rawResult= responseMessage.get("result");
    if (rawResult==null) {
      processException(responseMessage);
    }
    Class<?> returnType= method.getReturnType();
    if (returnType.equals(Void.TYPE))
View Full Code Here

    SerializerState state= new SerializerState();
    return message2Object.unmarshall(state, returnType, rawResult);
  }
 
  void processException(JSONObject responseMessage) {
    JSONObject error= (JSONObject)responseMessage.get("error");
    if (error!=null) {
      String trace= error.has("trace") ? error.getString("trace") : null;
      throw new ErrorResponse((Integer)error.get("code"),
        (String)error.get("msg"), trace)
    } else
      throw new ErrorResponse(JSONRPCResult.CODE_ERR_PARSE, "Unknown response:" + responseMessage.toString(2), null);
  }
View Full Code Here

    if (data.startsWith("{")) {
      return data;
    }
    if (data.startsWith("<title>")) {
      String old = data.replace("<title>", "").replace("</title>", "");
      return (new JSONObject(StrUtil.unpack06Title(old))).toString();
    }
    return "{en:'" + data + "'}";
  }
View Full Code Here

      getBusiness().getSystemService().getDatastore().put(e);
    }
  }

  private String convertAttributes(Map<String, String> attributes) {
    return new JSONObject(attributes).toString();
  }
View Full Code Here

    }

    public Variable executePlugin(Scraper scraper, ScraperContext context) {
        Variable body = executeBody(scraper, context);
        try {
            JSONObject jsonObject = XML.toJSONObject(body.toString());
            return new NodeVariable(jsonObject.toString());
        } catch (JSONException e) {
            throw new PluginException("Error converting XML to JSON: " + e.getMessage());
        }
    }
View Full Code Here

    }

    public Variable executePlugin(Scraper scraper, ScraperContext context) {
        Variable body = executeBody(scraper, context);
        try {
            JSONObject jsonObject = new JSONObject(body.toString());
            return new NodeVariable( XML.toString(jsonObject) );
        } catch (JSONException e) {
            throw new PluginException("Error converting JSON to XML: " + e.getMessage());
        }
    }
View Full Code Here

    private static final String SERVICE_URL =
        "http://localhost:8085/helloworld/HelloworldClientComponent/HelloworldClientBean";

    @Test
    public void testJSONRPCBinding() throws Exception {
        JSONObject jsonRequest = new JSONObject("{ \"method\": \"sayHello\", \"params\": [\"Ray\"], \"id\": 1}");

        WebConversation wc = new WebConversation();
        WebRequest request =
            new PostMethodWebRequest(SERVICE_URL, new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")),
                                     "application/json");
        WebResponse response = wc.getResource(request);

        Assert.assertEquals(200, response.getResponseCode());

        JSONObject jsonResp = new JSONObject(response.getText());
        String text = jsonResp.getString("result");
        Assert.assertTrue(text.endsWith("Hello Ray"));
    }
View Full Code Here

     * Makes a new component descriptor entry.
     */
    public EntryWriter(EntryType type)
    {
        m_type = type;
        m_json = new JSONObject();
        try
        {
            m_json.put("type", type.toString());
        }
        catch (JSONException e)
View Full Code Here

        try
        {
            Object[] parameters = annotation.get(attribute.toString());
            if (parameters != null)
            {
                JSONObject properties = new JSONObject();
                for (Object p : parameters)
                {
                    Annotation a = (Annotation) p;
                    String name = (String) a.get("name");
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.