Package org.json

Examples of org.json.JSONTokener


     */
    public Widget getMetadata(String url) {
        Widget widget = new WidgetImpl();
        JSONObject jsonGadget = null;
        try {
            jsonGadget = (JSONObject) new JSONTokener(gadgetMetadataRepository.getGadgetMetadata(url)).nextValue();
            if (jsonGadget != null) {
                String query = jsonGadget.getString("modulePrefs");
                if (query != null) {
                    JSONObject jsonModulePrefsObject = (JSONObject) new JSONTokener(query).nextValue();
                    if (jsonModulePrefsObject != null) {
                        widget.setTitle(parseProperty(jsonModulePrefsObject, "title"));
                        widget.setTitleUrl(parseProperty(jsonModulePrefsObject, "titleUrl"));
                        widget.setDescription(parseProperty(jsonModulePrefsObject, "description"));
                        widget.setAuthor(parseProperty(jsonModulePrefsObject, "author"));
                        widget.setAuthorEmail(parseProperty(jsonModulePrefsObject, "authorEmail"));
                        widget.setThumbnailUrl(parseProperty(jsonModulePrefsObject, "thumbnail"));
                        widget.setScreenshotUrl(parseProperty(jsonModulePrefsObject, "screenshot"));
                        widget.setUrl(url);
                        widget.setType(getSupportedContext());
                    }
                }
            }
        } catch (JSONException e) {
            try {
                String query = jsonGadget.getString("error");
                if (query != null) {
                    JSONObject jsonModuleErrorObject = (JSONObject) new JSONTokener(query).nextValue();
                    if (jsonModuleErrorObject != null) {
                        String errorMessage = jsonModuleErrorObject.getString("message");
                        String errorCode = jsonModuleErrorObject.getString("code");
                        throw new IllegalArgumentException("HTTP error: " + errorCode + ". Message: " + errorMessage);
                    }
View Full Code Here


    }

    public Object fromJSON(String s)
  throws UnmarshallException
    {
  JSONTokener tok =   new JSONTokener(s);
  Object json;
  try {
      json = tok.nextValue();
  } catch(JSONException e) {
      throw new UnmarshallException("couldn't parse JSON");
  }
  SerializerState state = new SerializerState();
  return unmarshall(state, null, json);
View Full Code Here

public class Common {
  public static final String TRIPLE_STORE_URL = "http://mmisw.org/sparql";

  public static void _showJson(String str) throws Exception {
    JSONTokener jsonParser = new JSONTokener(str);
    JSONObject jsonObj = new JSONObject(jsonParser);
    System.out.println("JSON:");
    System.out.println(jsonObj);
    JSONArray names = jsonObj.getJSONArray("names");
    JSONArray values = jsonObj.getJSONArray("values");
View Full Code Here

        /*
         * remove them from the default graph: Use a "delete data" statement, which
         * requires explicit triples (no template or variables):
         */
        JSONTokener jsonParser = new JSONTokener(result);
        JSONObject jsonObj = new JSONObject(jsonParser);
//      JSONArray names = jsonObj.getJSONArray("names");
        JSONArray values = jsonObj.getJSONArray("values");
        if ( values.length() > 0 ) {
            if ( log.isDebugEnabled() ) {
View Full Code Here

          sw.flush();
         
          fis.close();
          fis = null;
         
          JSONTokener tokener = new JSONTokener(sw.toString());
          Object infoObj = tokener.nextValue();
          if( infoObj instanceof JSONObject ) {
            JSONObject info = (JSONObject)infoObj;
           
            {
              String testName = info.optString(DocumentStoreProcess.ATT_INFO_NAME);
View Full Code Here

        size = isr.read(buffer);
      }
     
      sw.flush();
     
      JSONTokener tokener = new JSONTokener(sw.toString());
      result = tokener.nextValue();
     
    } catch (Exception e) {
      throw new Exception("Error while reading file: "+file.getName(), e);
     
    } finally {
View Full Code Here

     */
    public void testAcceptHeaderSet() throws JSONException, JAXBException {
        String s =
            client.resource(getBaseURI() + "/echoaccept").accept(MediaType.APPLICATION_JSON_TYPE)
                .get(String.class);
        JSONObject j = new JSONObject(new JSONTokener(s));
        assertEquals("echo: " + MediaType.APPLICATION_JSON, j.get("value"));

        s =
            client.resource(getBaseURI() + "/echoaccept").accept(MediaType.TEXT_XML)
                .get(String.class);
View Full Code Here

     */
    public void testAcceptHeaderSet() throws JSONException, JAXBException {
        String s =
            client.resource(getBaseURI() + "/echoaccept").accept(MediaType.APPLICATION_JSON_TYPE)
                .get(String.class);
        JSONObject j = new JSONObject(new JSONTokener(s));
        assertEquals("echo: " + MediaType.APPLICATION_JSON, j.get("value"));

        s =
            client.resource(getBaseURI() + "/echoaccept").accept(MediaType.TEXT_XML)
                .get(String.class);
View Full Code Here

                                                        "/test/jsonarray",
                                                        "application/json");
        MockHttpServletResponse response = invoke(request);
        assertEquals(200, response.getStatus());
        JSONArray result =
            new JSONArray(new JSONTokener(new StringReader(response.getContentAsString())));
        JSONArray want = new JSONArray(JSON_ARRAY);
        assertTrue(JSONUtils.equals(want, result));
    }
View Full Code Here

                                                        MediaType.APPLICATION_JSON,
                                                        JSON_ARRAY.getBytes());
        MockHttpServletResponse response = invoke(request);
        assertEquals(200, response.getStatus());
        JSONArray result =
            new JSONArray(new JSONTokener(new StringReader(response.getContentAsString())));
        JSONArray want = new JSONArray(JSON_ARRAY).put(Collections.singletonMap("foo", "bar"));
        assertTrue(JSONUtils.equals(want, result));
    }
View Full Code Here

TOP

Related Classes of org.json.JSONTokener

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.