Package org.json

Examples of org.json.JSONTokener


      http().executeMethod(null, postMethod, state);
      int statusCode= postMethod.getStatusCode();
      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) {
View Full Code Here


     */
    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

                throw new HttpException("Got status code " + result + " for call to " + method.getURI());
            }

            input = method.getResponseBodyAsStream();

            JSONObject object = new JSONObject(new JSONTokener(new InputStreamReader(input)));

            JSONArray bundleData = object.getJSONArray("data");
            for (int i = 0; i < bundleData.length(); i++) {
                JSONObject bundle = bundleData.getJSONObject(i);
                String remotebundleSymbolicName = bundle.getString("symbolicName");
View Full Code Here

  }

  @Override
  protected void loadPage() throws Exception {
    try {
      JSONTokener jsonTokener = new JSONTokener(new InputStreamReader(getInputStream()));
      char nextClean = jsonTokener.nextClean(); jsonTokener.back();
     
      switch (nextClean) {
      case '{':
        this.json = new ObjectNodeImpl(new JSONObject(jsonTokener));
        break;
View Full Code Here

          new NameValuePair("sort_item", "letter"),
          new NameValuePair("sort_type", "desc") };
      String contactsUrl = lastUrl.substring(0, lastUrl.lastIndexOf("/"))
          + "/addr_member.php";
      String json = doPost(contactsUrl, params);
      JSONTokener jsonTokener = new JSONTokener(json);
      Object o = jsonTokener.nextValue();
      JSONObject jsonObj = (JSONObject) o;
      JSONObject jsonData = jsonObj.getJSONObject("data");
      JSONArray jsonContacts = jsonData.getJSONArray("contact");
      List<Contact> contacts = new ArrayList<Contact>();
      for (int i = 0; i < jsonContacts.length(); i++) {
View Full Code Here

     * @return JSON对象
     * @throws org.json.JSONException
     */
    protected JSONObject parseJSON(String content, String startTag) throws JSONException {
        String json = content.substring(content.indexOf(startTag) + startTag.length());
        JSONTokener jsonTokener = new JSONTokener(json);
        Object o = jsonTokener.nextValue();
        return (JSONObject) o;
    }
View Full Code Here

     * @throws org.json.JSONException
     */
    protected JSONObject parseJSON(String content, String startTag, String endTag) throws JSONException {
        String sub_content = content.substring(content.indexOf(startTag) + startTag.length());
        String json = sub_content.substring(0, sub_content.indexOf(endTag));
        JSONTokener jsonTokener = new JSONTokener(json);
        Object o = jsonTokener.nextValue();
        return (JSONObject) o;
    }
View Full Code Here

            InputStream input = null;
            try {
                if (status == 200) {
                    input = httpMethod.getResponseBodyAsStream();
                    JSONObject obj = new JSONObject(new JSONTokener(new InputStreamReader(input)));
   
                    JSONArray bundleStatus = obj.getJSONArray("s");
   
                    int total = bundleStatus.getInt(0);
                    int active = bundleStatus.getInt(1);
View Full Code Here

        return " ["+resultCode+"]";
      }

            input = method.getResponseBodyAsStream();

            JSONObject result = new JSONObject(new JSONTokener(new InputStreamReader(input)));
            JSONArray dataArray = (JSONArray) result.get("data");
            JSONObject firstElement = (JSONObject) dataArray.get(0);
            return " ["+firstElement.get("state")+"]";
    } catch (Exception e) {
      e.printStackTrace();
View Full Code Here

  @Override
  public DBObject getQuery() {
    DBObject dbObj = ((CollectionBase) getParent()).getQuery();

    try {
      dbObj = mergeJson(new JSONObject(new JSONTokener(queryStr)), dbObj);
      return dbObj;
    } catch (JSONException e) {
      // TODO: handle this better!
      System.out.println("Failed to parse query str.");
    }
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.