public ArrayList<SpecificCategories> getSpecificCategory(Object res) {
    ArrayList<SpecificCategories> specificCategories = null;
    JSONObject object;
    try {
      object = new JSONObject(res.toString());
      JSONArray array = object.getJSONArray("specificCategories");
      if (array != null && !array.equals("[]")) {
        specificCategories = new ArrayList<SpecificCategories>();
        for (int i = 0; i < array.length(); i++) {
          SpecificCategories specificCategory = new SpecificCategories();
          JSONObject object2 = array.optJSONObject(i);

          specificCategory.setSpecificCategories_id(
              object2.optInt("specificCategories_id")); // 详细分类ID
          specificCategory.setAllCategories_id(object2.optInt("allCategories_id")); // 全部分类ID
          specificCategory.setSpecificCategories_name(
              object2.optString("specificCategories_name")); // 详细分类地址
          specificCategories.add(specificCategory);
        }
      }

    } catch (JSONException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return specificCategories;
  }
Example #2
0
  static final Quilt createFromJSONObject(JSONObject jsonObject) throws JSONException {

    int rowCount = jsonObject.optInt("rowCount", 0);
    int columnCount = jsonObject.optInt("columnCount", 0);
    float width = (float) jsonObject.optDouble("width", 0);
    float height = (float) jsonObject.optDouble("height", 0);

    Quilt quilt = new Quilt(rowCount, columnCount, width, height);

    if (jsonObject.has("quiltBlocks")) {
      JSONArray jsonQuiltBlocks = jsonObject.getJSONArray("quiltBlocks");

      int index = -1;
      for (int row = 0; row < quilt.m_rowCount; ++row) {
        for (int column = 0; column < quilt.m_columnCount; ++column) {
          index += 1;
          if (index < jsonQuiltBlocks.length()) {
            JSONObject jsonQuiltBlock = jsonQuiltBlocks.optJSONObject(index);
            if (jsonQuiltBlock != null) {
              QuiltBlock quiltBlock = QuiltBlock.createFromJSONObject(jsonQuiltBlock);
              quilt.setQuiltBlock(row, column, quiltBlock);
            }
          }
        }
      }
    }

    quilt.m_new = false;
    return quilt;
  }
Example #3
0
 private IGPSObject parseSUBFRAME(final JSONObject json) throws ParseException {
   IGPSObject gps;
   final SUBFRAMEObject subframe = new SUBFRAMEObject();
   subframe.setDevice(json.optString("device", null));
   subframe.setMSBs(json.optInt("TOW17"));
   subframe.setSatelliteNumber(json.optInt("tSV"));
   subframe.setSubframeNumber(json.optInt("frame"));
   subframe.setScaled(json.optBoolean("scaled", false));
   subframe.setPageid(json.optInt("pageid"));
   if (json.has("system_message")) {
     subframe.setSystemMessage(json.optString("system_message"));
   } else if (json.has(ALMANACObject.NAME)) {
     subframe.setAlmanac((ALMANACObject) this.parse(json.optJSONObject(ALMANACObject.NAME)));
   } else if (json.has(EPHEM1Object.NAME)) {
     subframe.setEphem1((EPHEM1Object) this.parse(json.optJSONObject(EPHEM1Object.NAME)));
   } else if (json.has(EPHEM2Object.NAME)) {
     subframe.setEphem2((EPHEM2Object) this.parse(json.optJSONObject(EPHEM2Object.NAME)));
   } else if (json.has(EPHEM3Object.NAME)) {
     subframe.setEphem3((EPHEM3Object) this.parse(json.optJSONObject(EPHEM3Object.NAME)));
   } else if (json.has(ERDObject.NAME)) {
     subframe.setErd((ERDObject) this.parse(json.optJSONObject(ERDObject.NAME)));
   } else if (json.has(HEALTHObject.NAME)) {
     subframe.setHealth((HEALTHObject) this.parse(json.optJSONObject(HEALTHObject.NAME)));
   } else if (json.has(HEALTH2Object.NAME)) {
     subframe.setHealth2((HEALTH2Object) this.parse(json.optJSONObject(HEALTH2Object.NAME)));
   } else if (json.has(IONOObject.NAME)) {
     subframe.setIono((IONOObject) this.parse(json.optJSONObject(IONOObject.NAME)));
   } else {
     AbstractResultParser.LOG.error("Unknown subframe: {}", json.toString());
   }
   gps = subframe;
   return gps;
 }
  public UserSmart(JSONObject objUser) {
    super();
    this.checkInId = objUser.optInt("checkin_id");
    this.userId = objUser.optInt("id");
    this.nickName = objUser.optString("nickname");
    this.statusText = objUser.optString("status_text");
    this.photo = objUser.optString("photo");
    this.majorJobCategory = objUser.optString("major_job_category");
    this.minorJobCategory = objUser.optString("minor_job_category");
    this.headLine = objUser.optString("headline");

    if (!objUser.optString("filename").equals("")) this.fileName = objUser.optString("filename");
    else if (!objUser.optString("imageUrl").equals(""))
      this.fileName = objUser.optString("imageUrl");
    else if (Constants.debugLog)
      Log.d(
          "UserSmart",
          "Warning, could not parse user image URL with keys 'filename' or 'imageUrl'...");

    this.lat = objUser.optDouble("lat");
    this.lng = objUser.optDouble("lng");
    this.checkedIn = objUser.optInt("checked_in");
    this.foursquareId = objUser.optString("foursquare");
    this.venueName = objUser.optString("venue_name");
    this.venueId = objUser.optInt("venue_id");
    this.checkInCount = objUser.optInt("checkin_count");
    this.skills = objUser.optString("skills");
    this.sponsorNickname = objUser.optString("sponsorNickname");
    if (this.sponsorNickname.equalsIgnoreCase("") == false) {
      Log.d("UserSmart", "Sponsor: %s" + this.sponsorNickname);
      int test = 5;
      int test2 = test;
    }
    this.met = objUser.optBoolean("met");
  }
  public void parseDiscoverList(String discovered, String url) {

    JSONObject page = new JSONObject(discovered);
    totalPages = page.optInt("total_pages");
    totalResults = page.optInt("total_results");

    resultsLeft = totalResults;

    System.out.println("DISC: " + discovered);
    JSONArray list = page.optJSONArray("results");
    System.out.println("LIST: " + list);

    parseDiscoverPage(list);

    if (totalPages > 40) {
      for (int i = 2; i <= 40; i++) {
        page = nextPage(url, i);
        if (page != null) {
          list = page.optJSONArray("results");
          parseDiscoverPage(list);
        }
      }
    } else {
      for (int i = 2; i <= totalPages; i++) {
        page = nextPage(url, i);
        if (page != null) {
          list = page.optJSONArray("results");
          parseDiscoverPage(list);
        }
      }
    }
  }
Example #6
0
  static VmValue createFrom(VmIsolate isolate, JSONObject obj) {
    if (obj == null) {
      return null;
    }

    // {"objectId":4,"kind":"object","text":"Instance of '_HttpServer@14117cc4'"}

    VmValue value = new VmValue(isolate);

    value.objectId = obj.optInt("objectId");
    value.classId = obj.optInt("classId");
    value.kind = obj.optString("kind");
    value.text = obj.optString("text");
    value.length = obj.optInt("length", 0);

    // for kind == function
    value.name = obj.optString("name");
    value.signature = obj.optString("signature");

    if (value.text == null && value.isFunction()) {
      value.text = value.name + value.signature;
    }

    return value;
  }
    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
      if (mAnswerArray == null) {
        if (view == null) {
          TextView textView = new TextView(mContext);
          textView.setText("暂无回答内容!");
          textView.setGravity(Gravity.CENTER);
          textView.setPadding(0, 10, 0, 10);
          textView.setTextSize(15);
          view = textView;
        }
        return view;
      }

      ViewHolder holder;
      if (view == null) {
        view = mInflater.inflate(R.layout.question_answer_item, null);
        holder = new ViewHolder();
        holder.mName = (TextView) view.findViewById(R.id.txt_name);
        holder.mContent = (TextView) view.findViewById(R.id.txt_content);
        holder.mTime = (TextView) view.findViewById(R.id.txt_time);
        holder.mPhoto = (ImageView) view.findViewById(R.id.img_photo);
        holder.mFlag = (ImageView) view.findViewById(R.id.txt_flag);
        view.setTag(holder);
      } else {
        holder = (ViewHolder) view.getTag();
      }
      try {
        JSONObject jsonObject = (JSONObject) mAnswerArray.get(i);
        holder.mName.setText(jsonObject.optString("user_name"));
        holder.mTime.setText(jsonObject.optString("time"));
        holder.mContent.setText(jsonObject.optString("answer_content"));
        int best = jsonObject.optInt("is_best");
        if (isOwnQuestion()) {
          holder.mFlag.setVisibility(View.VISIBLE);
          if (best == 0) {
            holder.mFlag.setImageResource(R.drawable.caina);
            holder.mFlag.setOnClickListener(
                new BastClickListener(jsonObject.optInt("answer_id"), 1));
          } else {
            holder.mFlag.setImageResource(R.drawable.zuijiadaan);
          }

        } else {
          if (best == 0) holder.mFlag.setVisibility(View.GONE);
          else {
            holder.mFlag.setVisibility(View.VISIBLE);
            holder.mFlag.setImageResource(R.drawable.zuijiadaan);
            ;
          }
        }
        NetComTools.getInstance(mContext)
            .loadNetImage(
                holder.mPhoto, jsonObject.optString("user_face"), R.drawable.header, 144, 144);
      } catch (Exception e) {
        e.printStackTrace();
      }

      return view;
    }
Example #8
0
 /** method to update data in caching layer object from JSON * */
 public boolean updateFromJSON(JSONObject jsonObj) {
   try {
     JSONArray hasArcsArray = jsonObj.optJSONArray("hasArcs");
     if (hasArcsArray != null) {
       ArrayList<Arc> aListOfHasArcs = new ArrayList<Arc>(hasArcsArray.length());
       for (int i = 0; i < hasArcsArray.length(); i++) {
         int id = hasArcsArray.optInt(i);
         if (ArcManager.getInstance().get(id) != null) {
           aListOfHasArcs.add(ArcManager.getInstance().get(id));
         }
       }
       setHasArcs(aListOfHasArcs);
     }
     if (!jsonObj.isNull("hasPropertySet")) {
       int hasPropertySetId = jsonObj.optInt("hasPropertySet");
       PropertySet value = PropertySetManager.getInstance().get(hasPropertySetId);
       if (value != null) {
         setHasPropertySet(value);
       }
     }
     if (!jsonObj.isNull("hasDomainNodes")) {
       int hasDomainNodesId = jsonObj.optInt("hasDomainNodes");
       NodeList value = NodeListManager.getInstance().get(hasDomainNodesId);
       if (value != null) {
         setHasDomainNodes(value);
       }
     }
   } catch (Exception e) {
     logWriter.error("Failure updating from JSON", e);
     return false;
   }
   return true;
 }
 @Override
 protected void onResult(JSONObject o) {
   try {
     // 获取状态码
     int value = o.optInt("result_code");
     setProcessStatus(value);
     if (value == 0) {
       JSONArray jsonUserInfoList = o.has("body") ? o.optJSONArray("body") : null;
       if (jsonUserInfoList != null) {
         for (int i = 0; i < jsonUserInfoList.length(); i++) {
           JSONObject jsonUser = jsonUserInfoList.getJSONObject(i);
           User user = new User();
           user.setUserId(jsonUser.optString("user_id"));
           user.setUserImId(jsonUser.optString("user_im_id"));
           user.setNickName(jsonUser.optString("nickname"));
           user.setPortraitURL(jsonUser.optString("portrait_url"));
           user.setGender(jsonUser.optInt("gender"));
           user.setSource(jsonUser.optString("source"));
           String blackList = jsonUser.optString("blacklist");
           if (blackList.equals("1")) {
             user.setInBlackList(true);
           }
           /*设置user header*/
           setUserHearder(user);
           contactList.add(user);
         }
       }
     } else {
       setStatus(ProcessStatus.Status.InfoNoData);
     }
   } catch (Exception e) {
     e.printStackTrace();
     setStatus(ProcessStatus.Status.ErrUnkown);
   }
 }
Example #10
0
 public SplashObj getSplashObj() {
   try {
     String json =
         HttpUtils.getHttpContentWithCache(
             BiliUtils.getSplashApi(), "splash", "splash.json", true);
     if (json == null) return null;
     JSONObject jsobj = new JSONObject(json);
     if (jsobj.optString("message").equals("success")) {
       JSONArray array = jsobj.getJSONArray("result");
       JSONObject temp = array.getJSONObject(0);
       SplashObj obj = new SplashObj();
       obj.setAnimation(temp.optString("animation"));
       obj.setDuration(temp.optString("duration"));
       obj.setEnd(temp.optLong("end"));
       obj.setHeight(temp.optInt("height"));
       obj.setImage(temp.optString("image"));
       obj.setStart(temp.optLong("start"));
       obj.setWidth(temp.optInt("width"));
       obj.setVer(temp.optInt("ver"));
       return obj;
     }
   } catch (JSONException e) {
   }
   return null;
 }
Example #11
0
  @Override
  public void parseJson(String jsonStr) {
    JSONObject jsonObject = getJsonObject(jsonStr);
    this.setAge(jsonObject.optString("age"));
    this.setImgUrl(jsonObject.optString("avatar"));
    this.setNickname(jsonObject.optString("nickname"));
    this.setHeight(jsonObject.optString("height"));
    this.setOnline(jsonObject.optInt("online"));
    this.setImgUrl(jsonObject.optString("avatar"));
    this.setUid(jsonObject.optLong("uid"));
    this.setProvince(jsonObject.optString("province"));
    this.setCity(jsonObject.optString("city"));
    this.setGrade(jsonObject.optInt("grade"));
    this.gender = jsonObject.optInt("gender");

    this.hasLocalTag = jsonObject.optBoolean("hasLocalTag");
    if (hasLocalTag) {
      this.localTag = new LocateTag();
      localTag.parseJson(jsonObject.optString("localTag"));
    }
    this.score = jsonObject.optInt("score");
    this.lat = jsonObject.optDouble("lat");
    this.lng = jsonObject.optDouble("lng");
    this.distance = LocationMgr.getDistance(lng, lat);
    this.certify_level = jsonObject.optInt("certify_level");
    this.setFollowed(jsonObject.optBoolean("following"));
    this.setTm(jsonObject.optString("tm"));
    JSONObject JsonStatus = jsonObject.optJSONObject("status");
    if (JsonStatus != null) {
      this.setShow(JsonStatus.optString("show"));
    }
  }
Example #12
0
 public Wind(JSONObject json) {
   this.speed = (float) json.optDouble(Wind.JSON_SPEED);
   this.deg = json.optInt(Wind.JSON_DEG, Integer.MIN_VALUE);
   this.gust = (float) json.optDouble(Wind.JSON_GUST);
   this.varBeg = json.optInt(Wind.JSON_VAR_BEG, Integer.MIN_VALUE);
   this.varEnd = json.optInt(Wind.JSON_VAR_END, Integer.MIN_VALUE);
 }
Example #13
0
    public void assertMatch(JSONObject json) {
      assertEquals(mPayloadType, json.optInt("type"));
      assertEquals(mClockRate, json.optInt("clockRate"));
      assertEquals(mEncodingName, json.optString("encodingName"));
      if (mChannels > 0) {
        assertEquals(mChannels, json.optInt("channels"));
      }
      if (mNackPli != null) {
        json.has("nackpli");
        assertEquals((boolean) mNackPli, json.optBoolean("nackpli"));
      }
      if (mNack != null) {
        json.has("nack");
        assertEquals((boolean) mNack, json.optBoolean("nack"));
      }
      if (mCcmFir != null) {
        json.has("ccmfir");
        assertEquals((boolean) mCcmFir, json.optBoolean("ccmfir"));
      }
      JSONObject jsonParameters = json.optJSONObject("parameters");
      if (mParameters != null) {
        assertNotNull(jsonParameters);
        assertEquals(mParameters.size(), jsonParameters.length());

        for (Map.Entry<String, Object> parameter : mParameters.entrySet()) {
          assertTrue(jsonParameters.has(parameter.getKey()));
          assertEquals(parameter.getValue(), jsonParameters.opt(parameter.getKey()));
        }
      } else {
        assertTrue(jsonParameters == null || jsonParameters.length() == 0);
      }
    }
Example #14
0
  public String parse(String s, BadgeDetailData badgeDetailData) {
    JSONObject jAData = null;
    String msg = "";
    int errCode = -1;

    try {
      jAData = new JSONObject(s);
      if (jAData.has("code")) {
        errCode = jAData.getInt("code");
      } else if (jAData.has("errcode")) {
        errCode = jAData.getInt("errcode");
      } else if (jAData.has("errorCode")) {
        errCode = jAData.getInt("errorCode");
      }
      if (jAData.has("jsession")) {
        UserNow.current().jsession = jAData.getString("jsession");
      }
      if (errCode == JSONMessageType.SERVER_CODE_OK) {
        JSONObject content = jAData.getJSONObject("content");
        badgeDetailData.id = content.optInt("id");
        badgeDetailData.name = content.optString("name");
        badgeDetailData.pic = content.optString("pic");
        badgeDetailData.intro = content.optString("intro");
        badgeDetailData.getCount = content.optInt("getCount");
        badgeDetailData.getTime = content.optInt("getTime");
      } else msg = jAData.getString("msg");
    } catch (JSONException e) {
      e.printStackTrace();
    }
    return msg;
  }
 /**
  * 获取用户收货地址信息getDefaultAddr:(这里用一句话描述这个方法的作用). <br>
  * TODO(这里描述这个方法适用条件 – 可选).<br>
  * TODO(这里描述这个方法的执行流程 – 可选).<br>
  * TODO(这里描述这个方法的使用方法 – 可选).<br>
  * TODO(这里描述这个方法的注意事项 – 可选).<br>
  *
  * @author chenhao
  * @return
  * @since JDK 1.6
  */
 public DefaultAddr getDefaultAddr() {
   DefaultAddr defaultAddr = null;
   List<NameValuePair> nv = new ArrayList<NameValuePair>();
   nv.add(new BasicNameValuePair("userno", Appcontents.userno));
   String request = Constant.URL + "user/defaultAddr";
   String strResult = HttpTools.getHttpRequestString(nv, request);
   // System.out.println("strResult" + strResult);
   if (!StringUtils.isEmpty(strResult)) {
     try {
       JSONObject jsonObject = new JSONObject(strResult);
       defaultAddr = new DefaultAddr();
       if (jsonObject.has("code")) {
         int code = jsonObject.optInt("code");
         if (code == 0) {
           defaultAddr.code = jsonObject.optInt("code");
           return defaultAddr;
         } else {
           defaultAddr.phone = jsonObject.getString("phone");
           defaultAddr.uname = jsonObject.getString("uname");
           defaultAddr.addr = jsonObject.getString("addr");
           defaultAddr.code = jsonObject.optInt("code");
           return defaultAddr;
         }
       }
     } catch (JSONException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
   }
   // System.out.println("defaultAddr===" + defaultAddr.addr);
   return defaultAddr;
 }
Example #16
0
 private void assertSctp(JSONObject mediaDescription, int port, String app, int streamCount) {
   JSONObject sctp = mediaDescription.optJSONObject("sctp");
   assertNotNull(sctp);
   assertEquals(port, sctp.optInt("port"));
   assertEquals(app, sctp.optString("app"));
   assertEquals(streamCount, sctp.optInt("streams"));
 }
    @Override
    public void onSuccess(JSONObject response) {
      JSONArray array = response.optJSONArray("list");

      List<User> usersToInsert = parseUsers(array);
      for (int i = 0; i < usersToInsert.size(); i++) {
        KidsLogger.d(
            LOG_TAG, String.format("Getting user : %s ", usersToInsert.get(i).getScreenName()));
        if (usersToInsert.get(i).getScreenName().equals("null")) {
          KidsLogger.d(
              LOG_TAG, String.format("Removing user : %s ", usersToInsert.get(i).getScreenName()));
          usersToInsert.remove(i);
        }
      }

      if (!insertNewUsers(usersToInsert)) {
        mCallback.onFailure(new IOException("Impossible to insert users in db."));
        return;
      }

      if (response.optBoolean("has_more") && response.optInt("page") != 0) {
        fetchPage(response.optInt("page") + 1);
      } else {
        deleteOutdatedUsers();
        mCallback.onSuccess(mFetchedUsers);
      }
    }
Example #18
0
  /**
   * @param 评论
   * @return
   */
  public static List<MarkIdentityBean> Common(String content) {
    List<MarkIdentityBean> dates = new ArrayList<MarkIdentityBean>();
    MarkIdentityBean markShopBean12 = new MarkIdentityBean();
    CommentBean commentBean = new CommentBean();
    try {
      JSONObject jsonobject = new JSONObject(content);

      commentBean.good = jsonobject.optInt("good");
      commentBean.common = jsonobject.optInt("common");
      commentBean.bad = jsonobject.optInt("bad");

      Message message = new Message();
      message.obj = commentBean;
      MarkPinglunActivity.handler.sendMessage(message);

      JSONArray ja = new JSONArray(jsonobject.getString("data"));

      for (int i = 0; i < ja.length(); i++) {

        markShopBean12 =
            JSON.parseObject(ja.getJSONObject(i).optString("identity"), MarkIdentityBean.class);
        markShopBean12.markCommentBean =
            JSON.parseObject(ja.getJSONObject(i).optString("comment"), MarkCommentBean.class);
        dates.add(markShopBean12);
      }
      return dates;
    } catch (JSONException e) {
      e.printStackTrace();
    }
    return dates;
  }
Example #19
0
  private int recoveryFromRecord() {
    if (config.recorder == null) {
      return 0;
    }
    byte[] data = config.recorder.get(recorderKey);
    if (data == null) {
      return 0;
    }
    String jsonStr = new String(data);
    JSONObject obj;
    try {
      obj = new JSONObject(jsonStr);
    } catch (JSONException e) {
      e.printStackTrace();
      return 0;
    }
    int offset = obj.optInt("offset", 0);
    long modify = obj.optLong("modify_time", 0);
    int fSize = obj.optInt("size", 0);
    JSONArray array = obj.optJSONArray("contexts");
    if (offset == 0
        || modify != modifyTime
        || fSize != size
        || array == null
        || array.length() == 0) {
      return 0;
    }
    for (int i = 0; i < array.length(); i++) {
      contexts[i] = array.optString(i);
    }

    return offset;
  }
Example #20
0
  /**
   * Mobile logins user.
   *
   * @param context the specified context
   * @param request the specified request
   * @param response the specified response
   * @throws ServletException servlet exception
   * @throws IOException io exception
   * @throws JSONException JSONException
   */
  @RequestProcessing(value = "/oauth/token", method = HTTPRequestMethod.POST)
  public void mobileLogin(
      final HTTPRequestContext context,
      final HttpServletRequest request,
      final HttpServletResponse response)
      throws ServletException, IOException, JSONException {
    final String error = "invalid grant";
    final String errorDescription =
        "The provided authorization grant is invalid, expired, revoked, does not match";
    final JSONRenderer renderer = new JSONRenderer();
    context.setRenderer(renderer);

    final JSONObject ret = new JSONObject();
    renderer.setJSONObject(ret);

    final String username = request.getParameter("username");
    final String password = request.getParameter("password");

    try {
      JSONObject user = userQueryService.getUserByName(username);
      if (null == user) {
        user = userQueryService.getUserByEmail(username);
      }

      if (null == user || null == password) {
        ret.put("error", error);
        ret.put("error_description", errorDescription);
        return;
      }

      if (UserExt.USER_STATUS_C_INVALID == user.optInt(UserExt.USER_STATUS)
          || UserExt.USER_STATUS_C_INVALID_LOGIN == user.optInt(UserExt.USER_STATUS)) {
        userMgmtService.updateOnlineStatus(user.optString(Keys.OBJECT_ID), "", false);
        ret.put("error", error);
        ret.put("error_description", errorDescription);
        return;
      }

      final String userPassword = user.optString(User.USER_PASSWORD);
      if (userPassword.equals(MD5.hash(password))) {
        final String ip = Requests.getRemoteAddr(request);
        userMgmtService.updateOnlineStatus(user.optString(Keys.OBJECT_ID), ip, true);
        ret.put(
            "access_token",
            "{\"userPassword\":\""
                + user.optString(User.USER_PASSWORD)
                + "\",\"userEmail\":\""
                + user.optString(User.USER_EMAIL)
                + "\"}");
        ret.put("token_type", "bearer");
        ret.put("scope", "user");
        ret.put("created_at", new Date().getTime());
      }
    } catch (final ServiceException e) {
      ret.put("error", error);
      ret.put("error_description", errorDescription);
    }
  }
 public static House createHouse(JSONObject jsonHouse) {
   return new House(
       jsonHouse.getString("name"),
       jsonHouse.optString("description", "A house"),
       jsonHouse.optInt("level", 0),
       jsonHouse.getInt("upgradeCost"),
       jsonHouse.getInt("cost"),
       jsonHouse.optInt("inhabitants", 0));
 }
 public void readFromJson(JSONObject paramJSONObject) {
   if (!paramJSONObject.isNull("text")) {
     mTextAtThreshold = paramJSONObject.optString("text");
   }
   mRedVal = paramJSONObject.optInt("red_val");
   mBlueVal = paramJSONObject.optInt("blue_val");
   mGreenVal = paramJSONObject.optInt("green_val");
   mThreshold = paramJSONObject.optInt("length");
 }
Example #23
0
 /**
  * JsonObject 转换实例
  *
  * @param obj
  * @throws JSONException
  */
 public PersonContacts(JSONObject obj) throws JSONException {
   keHuId = obj.optString("keHuId");
   lianXiRenId = obj.optString("lianXiRenId");
   lianXiRenIsDel = obj.optInt("lianXiRenIsDel");
   lianXiRenName = obj.optString("lianXiRenName");
   lianXiRenTel = obj.optString("lianXiRenTel");
   moRenLianXiRen = obj.optInt("moRenLianXiRen");
   shouJi = obj.optString("shouJi");
 }
  /**
   * Gets the latest comments with the specified fetch size.
   *
   * <p>The returned comments content is plain text.
   *
   * @param fetchSize the specified fetch size
   * @return the latest comments, returns an empty list if not found
   * @throws ServiceException service exception
   */
  public List<JSONObject> getLatestComments(final int fetchSize) throws ServiceException {
    final Query query =
        new Query()
            .addSort(Comment.COMMENT_CREATE_TIME, SortDirection.DESCENDING)
            .setCurrentPageNum(1)
            .setPageSize(fetchSize)
            .setPageCount(1);
    try {
      final JSONObject result = commentRepository.get(query);
      final List<JSONObject> ret =
          CollectionUtils.<JSONObject>jsonArrayToList(result.optJSONArray(Keys.RESULTS));

      for (final JSONObject comment : ret) {
        comment.put(Comment.COMMENT_CREATE_TIME, comment.optLong(Comment.COMMENT_CREATE_TIME));
        final String articleId = comment.optString(Comment.COMMENT_ON_ARTICLE_ID);
        final JSONObject article = articleRepository.get(articleId);
        comment.put(
            Comment.COMMENT_T_ARTICLE_TITLE,
            Emotions.clear(article.optString(Article.ARTICLE_TITLE)));
        comment.put(
            Comment.COMMENT_T_ARTICLE_PERMALINK, article.optString(Article.ARTICLE_PERMALINK));

        final String commenterId = comment.optString(Comment.COMMENT_AUTHOR_ID);
        final JSONObject commenter = userRepository.get(commenterId);

        if (UserExt.USER_STATUS_C_INVALID == commenter.optInt(UserExt.USER_STATUS)
            || Comment.COMMENT_STATUS_C_INVALID == comment.optInt(Comment.COMMENT_STATUS)) {
          comment.put(Comment.COMMENT_CONTENT, langPropsService.get("commentContentBlockLabel"));
        }

        if (Article.ARTICLE_TYPE_C_DISCUSSION == article.optInt(Article.ARTICLE_TYPE)) {
          comment.put(Comment.COMMENT_CONTENT, "....");
        }

        String content = comment.optString(Comment.COMMENT_CONTENT);
        content = Emotions.clear(content);
        content = Jsoup.clean(content, Whitelist.none());
        if (StringUtils.isBlank(content)) {
          comment.put(Comment.COMMENT_CONTENT, "....");
        } else {
          comment.put(Comment.COMMENT_CONTENT, content);
        }

        final String commenterEmail = comment.optString(Comment.COMMENT_AUTHOR_EMAIL);
        final String avatarURL = avatarQueryService.getAvatarURL(commenterEmail);
        commenter.put(UserExt.USER_AVATAR_URL, avatarURL);

        comment.put(Comment.COMMENT_T_COMMENTER, commenter);
      }

      return ret;
    } catch (final RepositoryException e) {
      LOGGER.log(Level.ERROR, "Gets user comments failed", e);
      throw new ServiceException(e);
    }
  }
Example #25
0
 public void parseJson(JSONObject jsonObject) throws JSONException {
   if (jsonObject != null) {
     super.parseJson(jsonObject);
     playsCounts = jsonObject.optLong("playsCounts", 0);
     isFinished = jsonObject.optInt("isFinished", 0);
     serialState = jsonObject.optInt("serialState", 0);
     trackId = jsonObject.getLong("trackId");
     trackTitle = jsonObject.getString("trackTitle");
   }
 }
Example #26
0
 private IGPSObject parseERD(final JSONObject json) {
   IGPSObject gps;
   final ERDObject erd = new ERDObject();
   erd.setAi(json.optInt("ai"));
   for (int index = 1; index <= 30; index++) {
     erd.setERDbyIndex(index - 1, json.optInt("ERD" + index));
   }
   gps = erd;
   return gps;
 }
Example #27
0
 private IGPSObject parsePRN(final JSONObject json) {
   IGPSObject gps;
   final SATObject sat = new SATObject();
   sat.setPRN(json.optInt("PRN", -1));
   sat.setAzimuth(json.optInt("az", -1));
   sat.setElevation(json.optInt("el", -1));
   sat.setSignalStrength(json.optInt("ss", -1));
   sat.setUsed(json.optBoolean("used", false));
   gps = sat;
   return gps;
 }
Example #28
0
  public static Visible parse(JSONObject jsonObject) {
    if (null == jsonObject) {
      return null;
    }

    Visible visible = new Visible();
    visible.type = jsonObject.optInt("type", 0);
    visible.list_id = jsonObject.optInt("list_id", 0);

    return visible;
  }
Example #29
0
 /**
  * 初始一个用户信息
  *
  * @param obj UserInfo的JsonObject对象
  */
 public UserInfo(JSONObject obj) {
   this.Account = obj.optString("UserAccount");
   this.Name = obj.optString("UserName");
   this.Mobile = obj.optString("UserMobile");
   this.CompanyName = obj.optString("CompanyName");
   this.CompanyID = obj.optInt("CompanyID");
   this.UserType = obj.optInt("UserType") == 0 ? "普通用户" : "管理员";
   this.Token = obj.optString("Token");
   this.userVersion = obj.optString("UserVersion");
   this.ID = obj.optString("ID");
 }
Example #30
0
  public Dispersion(final JSONObject dsJo) {
    final JSONObject jo = dsJo.optJSONObject("dispersion");

    if (jo != null) {
      this.setLimit(jo.optInt("limit", DEFAULT_LIMIT)); // optInt to avoid JSONException
      this.setShuffled(jo.optBoolean("shuffled", DEFAULT_SHUFFLED));
    } else if (dsJo.has("maxDnsIpsForLocation")) {
      // if no specific dispersion, use maxDnsIpsForLocation (should be DNS DSs only)
      this.setLimit(dsJo.optInt("maxDnsIpsForLocation", DEFAULT_LIMIT));
    }
  }