Example #1
0
  public static List<Stop> getStops(String data) throws JSONException {
    List<Stop> stops = new ArrayList<Stop>();

    JSONArray jsonArray = new JSONArray(data);

    for (int i = 0; i < jsonArray.length(); ++i) {
      JSONObject jsonObject = jsonArray.getJSONObject(i);

      try {
        stops.add(
            new Stop(
                0,
                jsonObject.getString("StopId"),
                jsonObject.getString("StopCode"),
                jsonObject.getString("StopName"),
                jsonObject.getString("StopDesc"),
                jsonObject.getDouble("StopLat"),
                jsonObject.getDouble("StopLng"),
                jsonObject.getInt("StopSequence"),
                jsonObject.getString("ZoneId"),
                jsonObject.getString("StopUrl"),
                jsonObject.getInt("LocationType"),
                jsonObject.getString("ParentStation")));

      } catch (Exception e) {
        Log.e("GTFSParser:getStops", "" + e.getMessage());
        e.printStackTrace();
      }
    }
    return stops;
  }
  public ArrayList<ElementManager> parseJSON(String jsonStr) {
    ArrayList<ElementManager> elementsList = new ArrayList<ElementManager>();
    try {
      JSONObject json = new JSONObject(jsonStr);
      if (json.has("searchAdvert")) {
        JSONObject jsonCategory = (JSONObject) json.get("searchAdvert");
        int result = jsonCategory.getInt("result");
        if (result == 1) {
          JSONArray jsonArray = jsonCategory.getJSONArray("list");
          for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject obj = jsonArray.getJSONObject(i);
            int advertid = obj.getInt("advert_id");
            String photo = obj.getString("photodata");
            String title = obj.getString("title");
            Log.d("Title : ", title);
            String city = Basic.cities[obj.getInt("cityPosition")];
            String price = String.valueOf(obj.getInt("price"));
            ElementManager element = new ElementManager(advertid, photo, title, city, price);
            elementsList.add(element);
          }
        }

      } else {
        Log.i("JSON ILANARA : ", "Ilanlari çekerken hata oluştu");
      }
    } catch (JSONException e) {
      e.printStackTrace();
    }
    return elementsList;
  }
Example #3
0
  public SlideModel(JSONObject ob) {
    if (ob == null) return;
    try {
      if (ob.has("id")) this.id = ob.getInt("id");
    } catch (Exception ex) {
    }

    try {
      if (ob.has("name")) this.name = ob.getString("name");
    } catch (Exception ex) {
    }

    try {
      if (ob.has("category_id")) this.categoryId = ob.getInt("category_id");
    } catch (Exception ex) {
    }

    try {
      if (ob.has("photo_path")) this.photo_path = ob.getString("photo_path");
    } catch (Exception ex) {
    }

    try {
      if (ob.has("alt")) this.alt = ob.getString("alt");
    } catch (Exception ex) {
    }

    try {
      if (ob.has("url")) this.url = ob.getString("url");
    } catch (Exception ex) {
    }
  }
  /** s Requests access tokens for the given user id and valid auth token. */
  private static List<AccessToken> requestAccessTokens(String userid, String authToken)
      throws JSONException {

    Map<String, String> params = new HashMap<String, String>();
    params.put("username", userid);
    params.put("authtoken", authToken);

    String json = post(new JSONObject(params));
    if (json == null) {
      return null;
    }

    List<AccessToken> accessTokens = new ArrayList<AccessToken>();
    JSONArray tokens = new JSONArray(json);
    for (int i = 0; i < tokens.length(); i++) {

      JSONObject host = tokens.getJSONObject(i);
      AccessToken token =
          new AccessToken(
              host.getString("token"),
              host.getString("host"),
              host.getString("type"),
              host.getInt("port"),
              host.getInt("expiration"));

      accessTokens.add(token);
    }

    return accessTokens;
  }
Example #5
0
 public static Weibo fromJson(JSONObject weiboJsonObj) throws JSONException {
   Weibo weibo = new Weibo();
   weibo.setMid(weiboJsonObj.getLong("mid"));
   weibo.setSource(weiboJsonObj.getString("source"));
   weibo.setCreateTime(weiboJsonObj.getString("created_at"));
   weibo.setText(weiboJsonObj.getString("text"));
   weibo.setReportsNum(weiboJsonObj.getInt("reposts_count"));
   weibo.setCommentsNum(weiboJsonObj.getInt("comments_count"));
   weibo.setAttitudeStatus(weiboJsonObj.getInt("attitudes_status"));
   weibo.setLikeCount(weiboJsonObj.getInt("like_count"));
   weibo.setBid(weiboJsonObj.getString("bid"));
   weibo.setAttitudesNum(weiboJsonObj.getInt("attitudes_count"));
   if (!weiboJsonObj.isNull("pics")) {
     JSONArray picsJsonArray = weiboJsonObj.getJSONArray("pics");
     for (int i = 0; i < picsJsonArray.length(); i++) {
       JSONObject picsJsonObj = picsJsonArray.getJSONObject(i);
       weibo.getPics().add(picsJsonObj.getString("url"));
     }
   }
   if (!weiboJsonObj.isNull("user")) {
     weibo.setUser(User.fromJson(weiboJsonObj.getJSONObject("user")));
   }
   if (!weiboJsonObj.isNull("retweeted_status")) {
     weibo.setSrcWeibo(Weibo.fromJson(weiboJsonObj.getJSONObject("retweeted_status")));
   }
   return weibo;
 }
  @Override
  public void selectKind(int kind) {
    this.kind = kind;
    JSONObject json = defMap.get(name);

    try {
      texture(json.getString("texture"));

      int width = json.getInt("width");

      TextureFilm film = new TextureFilm(texture, width, json.getInt("height"));

      bloodColor = json.optInt("bloodColor", 0xFFBB0000);
      levitating = json.optBoolean("levitating", false);
      framesInRow = texture.width / width;

      idle = readAnimation(json, "idle", film);
      run = readAnimation(json, "run", film);
      attack = readAnimation(json, "attack", film);
      die = readAnimation(json, "die", film);
      zap = attack.clone();

    } catch (Exception e) {
      GLog.w("Something bad happens when loading %s", name);
    }

    play(idle);
  }
 private VacancyModel parseVacancyInfo(String jsonResponceString) {
   VacancyModel model = new VacancyModel();
   ArrayList<VacancyItemModel> data = new ArrayList<VacancyItemModel>();
   try {
     JSONObject jObj = new JSONObject(jsonResponceString);
     JSONArray jItems = jObj.getJSONArray(JSON_PARAMETER_ITEMS);
     model.setPage(jObj.getInt(JSON_PARAMETER_PAGE));
     model.setPages(jObj.getInt(JSON_PARAMETER_PAGES));
     for (int i = 0; i < jItems.length(); i++) {
       JSONObject item = jItems.getJSONObject(i);
       VacancyItemModel modelItem = new VacancyItemModel();
       modelItem.setId(item.getInt(JSON_PARAMETER_ID));
       modelItem.setName(item.getString(JSON_PARAMETER_NAME));
       modelItem.setUrl((item.getString(JSON_PARAMETER_URL)));
       PublisherItemModel publisher = new PublisherItemModel();
       JSONObject jPublisher = item.getJSONObject(JSON_PARAMETER_EMPLOYER);
       publisher.setId(jPublisher.getInt(JSON_PARAMETER_ID));
       publisher.setName(jPublisher.getString(JSON_PARAMETER_NAME));
       SimpleDateFormat formatter =
           new SimpleDateFormat(DATE_FORMAT, activity.getResources().getConfiguration().locale);
       modelItem.setDate(formatter.parse(item.getString(JSON_PARAMETER_CREATED_AT)));
       JSONObject jIcons = jPublisher.optJSONObject(JSON_PARAMETER_LOGO);
       if (jIcons != null) {
         String iconUrl = jIcons.getString(JSON_PARAMETER_90);
         publisher.setIconUrl(iconUrl);
       }
       modelItem.setPublisher(publisher);
       data.add(modelItem);
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   model.setItems(data);
   return model;
 }
Example #8
0
 /**
  * 获取授权额度列表
  *
  * @param string
  * @return
  */
 public static Object getCreditLineModel(String string) {
   if (getResultInt(string) == 0) {
     try {
       JSONObject object = new JSONObject(string);
       JSONObject result = object.getJSONObject("result");
       JSONObject data1 = result.getJSONObject("data");
       JSONArray data2 = data1.getJSONArray("data");
       ArrayList<CreditLineModel> models = new ArrayList<>();
       for (int i = 0; i < data2.length(); i++) {
         JSONObject jsonObject = data2.getJSONObject(i);
         CreditLineModel model = new CreditLineModel();
         model.setAmount(jsonObject.getInt("amount"));
         model.setInit_amount(jsonObject.getInt("init_amount"));
         model.setRepairdepot_name(jsonObject.getString("repairdepot_name"));
         model.setUser_id(jsonObject.getInt("user_id"));
         models.add(model);
       }
       return models;
     } catch (JSONException e) {
       e.printStackTrace();
     }
     return null;
   } else {
     return getErrorValue(string);
   }
 }
Example #9
0
 /**
  * 获取售后通知
  *
  * @param string
  * @return
  */
 public static Object getSalesNotificationModel(String string) {
   if (getResultInt(string) == 0) {
     try {
       JSONObject object = new JSONObject(string);
       JSONObject result = object.getJSONObject("result");
       JSONObject data1 = result.getJSONObject("data");
       JSONArray data2 = data1.getJSONArray("data");
       ArrayList<SalesNotificationModel> models = new ArrayList<>();
       for (int i = 0; i < data2.length(); i++) {
         JSONObject jsonObject = data2.getJSONObject(i);
         SalesNotificationModel model = new SalesNotificationModel();
         model.setRepairdepot_name(jsonObject.getString("repairdepot_name"));
         model.setAftersales_bn(jsonObject.getInt("aftersales_bn"));
         model.setContents(jsonObject.getString("contents"));
         model.setCre_time(jsonObject.getInt("cre_time"));
         model.setService_id(jsonObject.getInt("service_id"));
         model.setUser_id(jsonObject.getInt("user_id"));
         model.setUser_photo(jsonObject.getString("user_photo"));
         models.add(model);
       }
       return models;
     } catch (JSONException e) {
       e.printStackTrace();
     }
     return null;
   } else {
     return getErrorValue(string);
   }
 }
    public static void setSuggested_Temp_Basal(JSONObject openAPSSuggest, Context c) {
      try {
        Suggested_Temp_Basal = new TempBasal();
        Notifications.clear(MainActivity.activity); // Clears any open notifications
        if (openAPSSuggest.has("rate")) { // Temp Basal suggested
          Suggested_Temp_Basal.rate = openAPSSuggest.getDouble("rate");
          Suggested_Temp_Basal.ratePercent = openAPSSuggest.getInt("ratePercent");
          Suggested_Temp_Basal.duration = openAPSSuggest.getInt("duration");
          Suggested_Temp_Basal.basal_type = openAPSSuggest.getString("temp");
          Suggested_Temp_Basal.basal_adjustemnt = openAPSSuggest.getString("basal_adjustemnt");

          if (openAPSSuggest
              .getString("openaps_mode")
              .equals("closed")) { // OpenAPS mode is closed, send command direct to pump
            pumpAction.setTempBasal(
                openAPSFragment.getSuggested_Temp_Basal(), MainActivity.activity);
          } else { // Make notification (Wear & Phone)
            Notifications.newTemp(openAPSSuggest, c);
          }
        }
      } catch (Exception e) {
        Crashlytics.logException(e);
        Toast.makeText(
                MainActivity.activity, "Crash in setSuggested_Temp_Basal", Toast.LENGTH_SHORT)
            .show();
      }
      currentOpenAPSSuggest = openAPSSuggest;
      update();
    }
  public sp_GetUnnotifieds_Result(JSONObject obj) {
    try {

      if (!obj.isNull("message")) message = obj.getString("message");

      if (!obj.isNull("device_id")) device_id = obj.getString("device_id");

      if (!obj.isNull("device_type")) device_type = obj.getInt("device_type");

      if (!obj.isNull("id")) id = obj.getString("id");

      if (!obj.isNull("user_id")) user_id = obj.getLong("user_id");

      if (!obj.isNull("is_sent")) is_sent = obj.getBoolean("is_sent");

      if (!obj.isNull("sent_time")) sent_time = obj.getString("sent_time");

      if (!obj.isNull("priority")) priority = obj.getInt("priority");

      if (!obj.isNull("type")) type = obj.getInt("type");

      if (!obj.isNull("bidding_id")) bidding_id = obj.getLong("bidding_id");

      if (!obj.isNull("provide_id")) provide_id = obj.getLong("provide_id");

      if (!obj.isNull("request_id")) request_id = obj.getLong("request_id");

    } catch (JSONException e) {
      e.printStackTrace();
    }
  }
  public ArrayList<JournalViewModel> getJournal(int cropid) {
    String jsonResult = null;
    ArrayList<JournalViewModel> journals = null;
    try {
      JournalServiceRepository journalRep = new JournalServiceRepository();
      jsonResult = journalRep.execute("/SelectJournalByCropId?crop_id=" + cropid).get();
      JSONArray jsonArray = new JSONArray(jsonResult);
      journals = new ArrayList<JournalViewModel>();
      for (int i = 0; i < jsonArray.length(); i++) {
        JSONObject jsonObj = jsonArray.getJSONObject(i);
        JournalViewModel journalModel = new JournalViewModel();
        journalModel.setJournalid(jsonObj.getInt("journalid"));
        journalModel.setDesc(jsonObj.getString("description"));
        journalModel.setJournalDate(
            new Date(ModelHelper.parseJsonDate(jsonObj.getString("dateentered"))));
        // journalModel.setPhoto();
        journalModel.setCropid(jsonObj.getInt("cropid"));

        journals.add(journalModel);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return journals;
  }
  @JavascriptInterface
  public void logEvent(String json) {
    try {
      JSONObject event = new JSONObject(json);

      String name = event.getString(JS_KEY_EVENT_NAME);
      EventType eventType = convertEventType(event.getInt(JS_KEY_EVENT_CATEGORY));
      Map<String, String> eventAttributes =
          convertToMap(event.optJSONObject(JS_KEY_EVENT_ATTRIBUTES));

      int messageType = event.getInt(JS_KEY_EVENT_DATATYPE);
      switch (messageType) {
        case JS_MSG_TYPE_PE:
          MParticle.getInstance().logEvent(name, eventType, eventAttributes);
          break;
        case JS_MSG_TYPE_PV:
          MParticle.getInstance().logScreen(name, eventAttributes);
          break;
        case JS_MSG_TYPE_OO:
          MParticle.getInstance().setOptOut(event.optBoolean(JS_KEY_OPTOUT));
          break;
        case JS_MSG_TYPE_CR:
          MParticle.getInstance().logError(name, eventAttributes);
          break;
        case JS_MSG_TYPE_SE:
        case JS_MSG_TYPE_SS:
          // swallow session start and end events, the native SDK will handle those.
        default:
      }

    } catch (JSONException jse) {
      ConfigManager.log(MParticle.LogLevel.WARNING, String.format(errorMsg, jse.getMessage()));
    }
  }
Example #14
0
  public static List<StopTime> getStopTimes(String data) throws JSONException {
    List<StopTime> stopTimes = new ArrayList<StopTime>();

    JSONArray jsonArray = new JSONArray(data);

    SimpleDateFormat currentDateFormat = new SimpleDateFormat("hh:mm:ss");
    SimpleDateFormat newDateFormat = new SimpleDateFormat("hh:mm aa");

    for (int i = 0; i < jsonArray.length(); ++i) {
      JSONObject jsonObject = jsonArray.getJSONObject(i);

      try {
        stopTimes.add(
            new StopTime(
                jsonObject.getString("TripId"),
                newDateFormat.format(currentDateFormat.parse(jsonObject.getString("ArrivalTime"))),
                newDateFormat.format(
                    currentDateFormat.parse(jsonObject.getString("DepartureTime"))),
                jsonObject.getString("StopId"),
                jsonObject.getString("StopHeadsign"),
                jsonObject.getInt("PickupType"),
                jsonObject.getInt("DropOffType"),
                jsonObject.getInt("StopSequence"),
                jsonObject.getString("StartStopId"),
                jsonObject.getString("FinalStopId")));
      } catch (Exception e) {
        Log.e("GTFSParser:getStopTimes", "" + e.getMessage());
        e.printStackTrace();
      }
    }
    return stopTimes;
  }
Example #15
0
    /**
     * Read task from json
     *
     * @param json
     * @param model
     * @param metadata
     * @throws JSONException
     */
    public static void taskFromJson(JSONObject json, Task model, ArrayList<Metadata> metadata)
        throws JSONException {
      metadata.clear();
      model.clearValue(Task.REMOTE_ID);
      model.setValue(Task.REMOTE_ID, json.getLong("id"));
      model.setValue(Task.FLAGS, 0);
      readUser(json.getJSONObject("user"), model, Task.USER_ID, Task.USER);
      readUser(json.getJSONObject("creator"), model, Task.CREATOR_ID, null);
      model.setValue(Task.COMMENT_COUNT, json.getInt("comment_count"));
      model.setValue(Task.TITLE, json.getString("title"));
      model.setValue(Task.IMPORTANCE, json.getInt("importance"));
      model.setValue(
          Task.DUE_DATE, model.createDueDate(Task.URGENCY_SPECIFIC_DAY, readDate(json, "due")));
      model.setValue(Task.COMPLETION_DATE, readDate(json, "completed_at"));
      model.setValue(Task.CREATION_DATE, readDate(json, "created_at"));
      model.setValue(Task.DELETION_DATE, readDate(json, "deleted_at"));
      model.setValue(Task.RECURRENCE, json.optString("repeat", ""));
      model.setValue(Task.NOTES, json.optString("notes", ""));
      model.setValue(Task.DETAILS_DATE, 0L);

      JSONArray tags = json.getJSONArray("tags");
      for (int i = 0; i < tags.length(); i++) {
        JSONObject tag = tags.getJSONObject(i);
        String name = tag.getString("name");
        Metadata tagMetadata = new Metadata();
        tagMetadata.setValue(Metadata.KEY, TagService.KEY);
        tagMetadata.setValue(TagService.TAG, name);
        tagMetadata.setValue(TagService.REMOTE_ID, tag.getLong("id"));
        metadata.add(tagMetadata);
      }
    }
Example #16
0
 /**
  * 获取站内信
  *
  * @param string
  * @return
  */
 public static ArrayList<MessageModel> getMessageLists(String string) {
   ArrayList<MessageModel> models = new ArrayList<>();
   try {
     JSONObject object = new JSONObject(string);
     JSONObject result = object.getJSONObject("result");
     JSONObject data = result.getJSONObject("data");
     JSONArray data1 = data.getJSONArray("data");
     for (int i = 0; i < data1.length(); i++) {
       JSONObject object1 = data1.getJSONObject(i);
       MessageModel model = new MessageModel();
       model.setNotice_id(object1.getInt("notice_id"));
       model.setFrom_id(object1.getString("from_id"));
       model.setTo_id(object1.getString("to_id"));
       model.setType(object1.getString("type"));
       model.setTitle(object1.getString("title"));
       model.setContent(object1.getString("content"));
       model.setCreate_time(object1.getInt("create_time"));
       model.setStatus(object1.getString("status"));
       model.setUser_name(object1.getString("user_name"));
       models.add(model);
     }
   } catch (JSONException e) {
     e.printStackTrace();
   }
   return models;
 }
 /**
  * 获取新闻回复内容
  *
  * @param nid 新闻编号
  */
 private void getComments(int nid) {
   String url = "http://192.168.3.80:9292/getComments";
   String params = "nid=" + nid + "&startnid=0&count=10";
   SyncHttp http = new SyncHttp();
   try {
     String retStr = http.httpGet(url, params);
     JSONObject jsonObject = new JSONObject(retStr);
     int retCode = jsonObject.getInt("ret");
     if (retCode == 0) {
       JSONObject dataObject = jsonObject.getJSONObject("data");
       // 获取返回数目
       int totalnum = dataObject.getInt("totalnum");
       if (totalnum > 0) {
         // 获取返回新闻集合
         JSONArray commsList = dataObject.getJSONArray("commentslist");
         for (int i = 0; i < commsList.length(); i++) {
           JSONObject commsObject = (JSONObject) commsList.opt(i);
           HashMap<String, Object> hashMap = new HashMap<String, Object>();
           hashMap.put("cid", commsObject.getInt("cid"));
           hashMap.put("commentator_from", commsObject.getString("region"));
           hashMap.put("comment_content", commsObject.getString("content"));
           hashMap.put("comment_ptime", commsObject.getString("ptime"));
           mCommsData.add(hashMap);
         }
       } else {
         Toast.makeText(CommentsActivity.this, R.string.no_comments, Toast.LENGTH_LONG).show();
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
     Toast.makeText(CommentsActivity.this, R.string.get_comms_failure, Toast.LENGTH_LONG).show();
   }
 }
Example #18
0
 /**
  * 获取登录信息
  *
  * @param string
  * @return
  */
 public static Object getLoginModel(String string) {
   if (getResultInt(string) == 0) {
     try {
       JSONObject object = new JSONObject(string);
       JSONObject result = object.getJSONObject("result");
       int type = result.getInt("type");
       if (type == 0) {
         JSONObject data = result.getJSONObject("data");
         LoginModel model = new LoginModel();
         model.setRole_id(data.getInt("role_id"));
         model.setSeller_id(data.getInt("seller_id"));
         model.setShop_id(data.getInt("shop_id"));
         model.setHead_photo(data.getString("head_photo"));
         model.setDeposit(data.getString("deposit"));
         model.setAccount_name(data.getString("account_name"));
         model.setSum(data.getString("sum"));
         model.setCount(data.getString("count"));
         model.setLastMonthIncome(data.getString("lastMonthIncome"));
         model.setCurMonthIncome(data.getString("curMonthIncome"));
         model.setLogin_phone(data.getString("login_phone"));
         return model;
       } else if (type == 2) {
         return result.getString("info");
       }
     } catch (JSONException e) {
       e.printStackTrace();
     }
     return null;
   } else {
     return getErrorValue(string);
   }
 }
Example #19
0
  @Override
  public void postProcess() {

    if (result == null) {
      bChat.sendMessage(
          player,
          Language.GetTranslated("other.not_available") /*"&6Not available at the moment"*/);
      return;
    }
    try {
      int length = result.getInt("_size");
      String friends = "";
      bChat.sendMessage(player, "&6Your Friends &e   (&2online&6:&enot online)");
      for (int i = 0; i < length; i++) {
        JSONObject result2 = result.getJSONObject(String.valueOf(i));
        friends +=
            (result2.getInt("online") == 1 ? "&2" : "&e") + result2.getString("friend") + ", ";
      }
      friends = friends.substring(0, friends.length() - 2);
      bChat.sendMessage(player, friends);
    } catch (Exception e) {
      if (glizer.D) e.printStackTrace();
      bChat.sendMessage(player, "&6You haven't added any friends yet.");
    }
  }
Example #20
0
  public static Photo fromJsonSingle(JSONObject jsonObject) {
    Photo b = new Photo();
    // Deserialize json into object fields
    try {
      b.id = jsonObject.getInt("id");
      b.album_id = jsonObject.getInt("album_id");
      b.owner_id = jsonObject.getInt("owner_id");
      b.photo_75 = jsonObject.getString("photo_75");
      b.photo_130 = jsonObject.getString("photo_130");
      // b.photo_604 = jsonObject.getString("photo_604");
      // b.photo_807 = jsonObject.getString("photo_807");//TODO not sure about those photo sizes
      // b.width = jsonObject.getInt("width");
      // b.height = jsonObject.getInt("height");
      // b.text = jsonObject.getString("text");
      // b.access_key = jsonObject.getString("access_key");
      // b.post_source_type = jsonObject.getJSONObject("post_source").getString("type");
      // b.comments_count = jsonObject.getJSONObject("comments").getInt("count");
      // b.likes_count = jsonObject.getJSONObject("likes").getInt("count");
      // b.reposts_count = jsonObject.getJSONObject("reposts").getInt("count");

    } catch (JSONException e) {
      e.printStackTrace();
      Log.e(TAG, "Error processing JSONObject  " + jsonObject.toString());
      return null;
    }
    // Return new object
    return b;
  }
 @Override
 protected final void onPostExecute(JSONObject result) {
   if (result == null) {
     onFail(ResponseCode.SERVER_ERROR);
   } else {
     try {
       int response_code = result.getInt("response_code");
       if (response_code == ResponseCode.BUDDY_OK) {
         JSONArray comments = result.getJSONArray("comments");
         ArrayList<Comment> comment_list = new ArrayList<Comment>();
         for (int i = 0; i < comments.length(); i++) {
           JSONObject element = comments.getJSONObject(i);
           comment_list.add(
               new Comment(
                   element.getInt("uid"),
                   element.getString("username"),
                   element.getLong("timestamp"),
                   element.getString("content")));
         }
         onSuccess(comment_list);
       } else {
         onFail(response_code);
       }
     } catch (JSONException ex) {
       Log.d("Error", ex.toString());
       onFail(ResponseCode.SERVER_ERROR);
     }
   }
 }
  public static ItemDescription_Controller makebasicsearch1(org.json.JSONObject jsonObject)
      throws JSONException, org.json.JSONException {
    System.out.println("\n \n*****Inside Item Description Model Page!!******");
    ItemDescription_Controller bs7 = new ItemDescription_Controller();

    try {

      bs7.setShid(jsonObject.getInt("shid"));
      bs7.setPrice(jsonObject.getDouble("price"));
      bs7.setImage(jsonObject.getString("img"));
      bs7.setShoenme(jsonObject.getString("shoe_name"));
      bs7.setBrand(jsonObject.getString("b_name"));
      bs7.setSubc(jsonObject.getString("sc_name"));
      bs7.setDescp(jsonObject.getString("originaldescp"));
      bs7.setIStore(jsonObject.getInt("irving"));
      bs7.setDStore(jsonObject.getInt("dallas"));
      bs7.setPStore(jsonObject.getInt("plano"));
      bs7.setHStore(jsonObject.getInt("houston"));
      bs7.setAStore(jsonObject.getInt("arlington"));
      // bs.setToken(tlen);

    } catch (JSONException e) {
      System.out.println("Error: Parsing JSON " + e.getMessage());
    }
    return bs7;
  }
  public static List<Task> getTasksByUser(int userId) {

    List<Task> tasks = new ArrayList<Task>();

    NoJsonHttpRequest getRequest =
        new NoJsonHttpRequest(serverUrl, tasksPath + "?ownerId=" + userId, "GET");
    getRequest.addHeaderParameter(authorizationHeaderName, Util.base64Header);

    int statusCode = getRequest.execute();

    if (statusCode >= 300) {
      return tasks;
    }

    String response = getRequest.getResponse();

    try {
      JSONArray ja = new JSONArray(response);
      for (int i = 0; i < ja.length(); i++) {
        JSONObject jo = ja.getJSONObject(i);
        tasks.add(
            new Task(
                jo.getInt("id"),
                jo.getString("description"),
                jo.getInt("managerId"),
                jo.getInt("ownerId"),
                jo.getString("deadline"),
                jo.getString("status")));
      }
    } catch (JSONException e) {
      e.printStackTrace();
    }

    return tasks;
  }
Example #24
0
  public static URL parseURLFromBingJSON(String jsonString, int desiredOrientation)
      throws Exception {
    JSONArray imageResults =
        new JSONObject(jsonString)
            .getJSONObject("d")
            .getJSONArray("results")
            .getJSONObject(0)
            .getJSONArray("Image");
    if (imageResults != null && imageResults.length() > 0) {
      for (int i = 0; i < imageResults.length(); i++) {
        JSONObject imageResult = imageResults.getJSONObject(i);
        boolean tooBig = imageResult.getInt("FileSize") > Constants.MAX_IMAGE_FILE_SIZE_IN_BYTES;

        if (tooBig == false) {
          int width = imageResult.getInt("Width");
          int height = imageResult.getInt("Height");

          if (desiredOrientation == Configuration.ORIENTATION_PORTRAIT) {
            if (height > width) {
              return new URL(imageResult.getString("MediaUrl"));
            }
          } else if (desiredOrientation == Configuration.ORIENTATION_LANDSCAPE) {
            if (width > height) {
              return new URL(imageResult.getString("MediaUrl"));
            }
          }
        }
      }
    }

    return null;
  }
Example #25
0
  private void parseJSONArray(JSONArray checkIns) {

    if (checkIns == null) return;

    try {
      for (int i = 0; i < checkIns.length(); i++) {
        JSONObject checkIn = checkIns.getJSONObject(i);

        NotUsedCheckInPostItem postItem = new NotUsedCheckInPostItem();

        postItem.setCheckInId(checkIn.getLong(TAG_CHECKIN));
        Log.d(LOGTAG, "TEST ::: checkin post item id : " + checkIn.getLong(TAG_CHECKIN));
        postItem.setAuthorId(checkIn.getInt(TAG_AUTHOR));
        postItem.setPageId(checkIn.getInt(TAG_PAGE));
        postItem.setAppId(checkIn.getInt(TAG_APP));
        postItem.setPostId(checkIn.getString(TAG_POST));
        postItem.setTaggedIds(checkIn.getJSONArray(TAG_TAGGED_IDS));

        JSONObject coordObject = checkIn.getJSONObject(TAG_COORDS);
        postItem.setCoords(
            coordObject.getDouble(TAG_COORDS_LONG), coordObject.getDouble(TAG_COORDS_LAT));

        postItem.setTimeStamp(checkIn.getInt(TAG_TIMESTAMP));
        postItem.setMessage(checkIn.getString(TAG_MESSAGE));
      }
    } catch (JSONException e) {
      e.printStackTrace();
    }
  }
  @Override
  public int parse(String s) {

    JSONObject jObject = null;
    if (!isEmpty(s)) {
      try {
        jsonErrCode = ItvEngine.EVENT_OK;
        jObject = new JSONObject(s);
        if (jObject.getInt("errorcode") == jsonErrCode && jObject.has(DataSet.currentDate)) {
          JSONObject time = jObject.getJSONObject(DataSet.currentDate);
          JSONObject duration = time.getJSONObject(String.valueOf(DataSet.currentDuration));
          JSONArray array2 = jObject.getJSONArray("category");
          DataSet.currentTvChannels.clear();
          for (int i = 0; i < array2.length(); i++) {
            JSONObject categoryObject = array2.getJSONObject(i);
            Category category = new Category();
            category.id = categoryObject.getInt("id");
            category.name = categoryObject.getString("name");
            parseData(duration.getJSONArray(category.name), category);
          }

        } else {
          jsonErrCode = ItvEngine.EVENT_ERROR;
        }
      } catch (Exception e) {
        jsonErrCode = ItvEngine.EVENT_ERROR;
        e.printStackTrace();
      }
    }
    return jsonErrCode;
  }
  public void checkTilesReporting(String localeCode) throws JSONException {
    // Slight hack: Force top sites grid to reload.
    inputAndLoadUrl(StringHelper.ABOUT_BLANK_URL);
    inputAndLoadUrl(StringHelper.ABOUT_HOME_URL);

    // Click the first tracking tile and verify the posted data.
    JSONObject response = clickTrackingTile(StringHelper.DISTRIBUTION1_LABEL);
    mAsserter.is(response.getInt("click"), 0, "JSON click index matched");
    mAsserter.is(response.getString("locale"), localeCode, "JSON locale code matched");
    mAsserter.is(
        response.getString("tiles"),
        "[{\"id\":123},{\"id\":456},{\"id\":632},{\"id\":629},{\"id\":630},{\"id\":631}]",
        "JSON tiles data matched");

    inputAndLoadUrl(StringHelper.ABOUT_HOME_URL);

    // Pin the second tracking tile.
    pinTopSite(StringHelper.DISTRIBUTION2_LABEL);

    // Click the second tracking tile and verify the posted data.
    response = clickTrackingTile(StringHelper.DISTRIBUTION2_LABEL);
    mAsserter.is(response.getInt("click"), 1, "JSON click index matched");
    mAsserter.is(
        response.getString("tiles"),
        "[{\"id\":123},{\"id\":456,\"pin\":true},{\"id\":632},{\"id\":629},{\"id\":630},{\"id\":631}]",
        "JSON tiles data matched");

    inputAndLoadUrl(StringHelper.ABOUT_HOME_URL);

    // Unpin the second tracking tile.
    unpinTopSite(StringHelper.DISTRIBUTION2_LABEL);
  }
Example #28
0
  private UserModel user(JSONObject jsonObject, int type, String account) throws JSONException {
    // TODO Auto-generated method stub
    // JSON包含id name screen_name location gender birthday description profile_image_url
    // profile_image_url_large
    // url protected followers_count friends_count favourites_count  statuses_count following
    // notifications
    // created_at utc_offset  profile_background_color profile_text_color profile_link_color
    // profile_sidebar_fill_color
    // profile_sidebar_border_color profile_background_image_url profile_background_tile
    UserModel model = new UserModel();
    model.setId(jsonObject.getString("id"));
    model.setAccount(this.account); // 全局
    model.setOwner(account); // 本地

    model.setType(type);
    model.setFlag(0);

    model.setRawid(0);
    model.setTime(FanFouParser.date(jsonObject.getString("created_at")).getTime());

    model.setName(jsonObject.getString("name"));
    model.setScreenName(jsonObject.getString("screen_name"));
    model.setLocation(jsonObject.getString("location"));
    model.setGender(jsonObject.getString("gender"));
    model.setBirthday(jsonObject.getString("birthday"));
    model.setDescription(jsonObject.getString("description"));

    model.setProfileImageUrl(jsonObject.getString("profile_image_url"));
    model.setProfileImageUrlLarge(jsonObject.getString("profile_image_url_large"));
    model.setUrl(jsonObject.getString("url"));

    if (jsonObject.has("status")) {
      JSONObject so = jsonObject.getJSONObject("status");
      model.setStatus(so.getString("text"));
    }

    model.setFollowersCount(jsonObject.getInt("followers_count"));
    model.setFriendsCount(jsonObject.getInt("friends_count"));
    model.setFavouritesCount(jsonObject.getInt("favourites_count"));
    model.setStatusesCount(jsonObject.getInt("statuses_count"));

    model.setFollowing(jsonObject.getBoolean("following"));
    model.setProtect(jsonObject.getBoolean("protected"));
    model.setNotifications(jsonObject.getBoolean("notifications"));
    model.setVerified(false);
    model.setFollowMe(false);

    LogUtil.d(
        TAG,
        "user() id="
            + model.getId()
            + " type="
            + model.getType()
            + " owner="
            + model.getOwner()
            + " account="
            + model.getAccount());

    return model;
  }
Example #29
0
 private void handleLinkFavicon(final JSONObject message) throws JSONException {
   if (mContentDelegate != null) {
     int id = message.getInt("tabID");
     mContentDelegate.onReceivedFavicon(
         GeckoView.this, new Browser(id), message.getString("href"), message.getInt("size"));
   }
 }
Example #30
0
  public static List<Route> getRoutes(String data) throws JSONException {
    List<Route> routes = new ArrayList<Route>();

    JSONArray jsonArray = new JSONArray(data);

    for (int i = 0; i < jsonArray.length(); ++i) {
      JSONObject jsonObject = jsonArray.getJSONObject(i);

      try {
        routes.add(
            new Route(
                0,
                jsonObject.getInt("RouteId"),
                jsonObject.getString("AgencyId"),
                jsonObject.getString("RouteShortName"),
                jsonObject.getString("RouteLongName"),
                jsonObject.getInt("RouteType"),
                jsonObject.getString("RouteColor"),
                jsonObject.getString("RouteTextColor"),
                jsonObject.getString("RouteHeading")));
      } catch (Exception e) {
        Log.e("GTFSParser:getRoutes", "" + e.getMessage());
        e.printStackTrace();
      }
    }
    return routes;
  }