Example #1
0
  public static RouteModel ParseJSON(String json) throws JSONException {
    RouteModel route = new RouteModel();

    ArrayList<Step> localSteps = new ArrayList<RouteModel.Step>();

    // JSONをパース
    JSONObject obj = new JSONObject(json);
    JSONArray routelist = obj.getJSONArray("routes");
    JSONObject mainroute = routelist.getJSONObject(0);
    JSONArray legslist = mainroute.getJSONArray("legs");
    for (int i = 0; i < legslist.length(); i++) {
      JSONArray steps = legslist.getJSONObject(i).getJSONArray("steps");
      for (int j = 0; j < steps.length(); j++) {
        Step s = route.new Step();
        JSONObject step = steps.getJSONObject(j);
        s.distance = step.getJSONObject("distance").getInt("value");
        s.duration = step.getJSONObject("duration").getInt("value");
        JSONObject st = step.getJSONObject("start_location");
        s.start_addr =
            new GeoPoint((int) (st.getDouble("lat") * 1E6), (int) (st.getDouble("lng") * 1E6));
        JSONObject en = step.getJSONObject("end_location");
        s.end_addr =
            new GeoPoint((int) (en.getDouble("lat") * 1E6), (int) (en.getDouble("lng") * 1E6));
        s.instruction = step.getString("html_instructions");
        localSteps.add(s);
      }
    }

    route.steps = new Step[localSteps.size()];
    for (int i = 0; i < localSteps.size(); i++) {
      route.steps[i] = localSteps.get(i);
    }

    return route;
  }
 @Override
 protected String doInBackground(String... params) {
   weather =
       Json.getJson(
           "http://api.wunderground.com/api/a8893cf69013d65a/conditions/q/"
               + myLocationNetwork.getLatitude()
               + ","
               + myLocationNetwork.getLongitude()
               + ".json");
   // Log.d("JG",""+ weather.toString());
   JSONObject currentObservationJson = null;
   JSONObject displayLocationJson = null;
   try {
     currentObservationJson = weather.getJSONObject("current_observation");
     displayLocationJson = currentObservationJson.getJSONObject("display_location");
   } catch (JSONException e) {
     e.printStackTrace();
   }
   try {
     temp = currentObservationJson.getString("temp_f");
     icon = currentObservationJson.getString("icon_url");
     Location = displayLocationJson.getString("full");
     city = displayLocationJson.getString("city");
     state = displayLocationJson.getString("state");
     Latitude = displayLocationJson.getString("latitude");
     Longitude = displayLocationJson.getString("longitude");
     Elevation = displayLocationJson.getString("elevation");
   } catch (JSONException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   return "";
 }
  /** Positive test case for listUsers method with optional parameters. */
  @Test(
      groups = {"wso2.esb"},
      description = "tsheets {listUsers} integration test with optional parameters.")
  public void testListUsersWithOptionalParameters() throws IOException, JSONException {

    esbRequestHeadersMap.put("Action", "urn:listUsers");
    RestResponse<JSONObject> esbRestResponse =
        sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_listUsers_optional.json");

    JSONObject esbUsers = esbRestResponse.getBody().getJSONObject("results").getJSONObject("users");

    String apiEndPoint =
        connectorProperties.getProperty("apiUrl") + "/api/v1/users?page=2&per_page=1";
    RestResponse<JSONObject> apiRestResponse =
        sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);

    JSONObject apiUsers = apiRestResponse.getBody().getJSONObject("results").getJSONObject("users");

    Iterator<String> esbUserKeySet = esbUsers.keys();

    Assert.assertEquals(apiUsers.length(), esbUsers.length());

    while (esbUserKeySet.hasNext()) {

      String userKey = esbUserKeySet.next();
      JSONObject esbUser = esbUsers.getJSONObject(userKey);
      JSONObject apiUser = apiUsers.getJSONObject(userKey);

      Assert.assertEquals(apiUser.getString("first_name"), esbUser.getString("first_name"));
      Assert.assertEquals(apiUser.getString("last_name"), esbUser.getString("last_name"));
      Assert.assertEquals(apiUser.getString("username"), esbUser.getString("username"));
      Assert.assertEquals(apiUser.getString("email"), esbUser.getString("email"));
    }
  }
  private static List<Box> parseBoundingBoxes(JSONArray jPositions) throws JSONException {
    List<Box> boxes = new ArrayList<Box>();
    for (int i = 0; i < jPositions.length(); i++) {
      JSONObject jBox = jPositions.getJSONObject(i);

      Point topLeft = null;
      Point bottomRight = null;
      Integer page = null;

      if (jBox.has("page")) {
        page = jBox.getInt("page");
      }
      if (jBox.has("top_left")) {
        JSONObject jTopLeft = jBox.getJSONObject("top_left");
        topLeft = new Point(jTopLeft.getDouble("x"), jTopLeft.getDouble("y"));
      }
      if (jBox.has("bottom_right")) {
        JSONObject jBottomRight = jBox.getJSONObject("bottom_right");
        bottomRight = new Point(jBottomRight.getDouble("x"), jBottomRight.getDouble("y"));
      }

      Box box = new Box(topLeft, bottomRight, page);
      boxes.add(box);
    }
    return boxes;
  }
  public static ArrayList<ContentProviderOperation> quoteJsonToContentVals(String JSON)
      throws JSONException {
    ArrayList<ContentProviderOperation> batchOperations = new ArrayList<>();
    JSONObject jsonObject = null;
    JSONArray resultsArray = null;
    ContentProviderOperation cpo = null;

    jsonObject = new JSONObject(JSON);
    if (jsonObject != null && jsonObject.length() != 0) {
      jsonObject = jsonObject.getJSONObject(QUERY);
      int count = Integer.parseInt(jsonObject.getString(COUNT));
      if (count == 1) {
        jsonObject = jsonObject.getJSONObject(RESULTS).getJSONObject(QUOTE);
        cpo = buildBatchOperation(jsonObject);
        if (cpo != null) {
          batchOperations.add(cpo);
        }

      } else {
        resultsArray = jsonObject.getJSONObject(RESULTS).getJSONArray(QUOTE);

        if (resultsArray != null && resultsArray.length() != 0) {
          for (int i = 0; i < resultsArray.length(); i++) {
            jsonObject = resultsArray.getJSONObject(i);
            cpo = buildBatchOperation(jsonObject);
            if (cpo != null) {
              batchOperations.add(cpo);
            }
          }
        }
      }
    }

    return batchOperations;
  }
  @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;
  }
  private User[] parseJson(String json) {
    // TODO: put results into list and display it

    // System.out.print(json);

    User[] users = null;

    try {
      JSONArray jsonArr = new JSONArray(json);
      users = new User[jsonArr.length()];

      Random rand = new Random();
      for (int i = 0; i < jsonArr.length(); i++) {
        JSONObject obj = jsonArr.getJSONObject(i);
        User u =
            new User(
                obj.getInt("id"),
                obj.getJSONObject("user").getString("username"),
                String.valueOf(rand.nextInt((400 - 50) + 1) + 50),
                obj.getJSONObject("user").getString("number"),
                Float.parseFloat(obj.getJSONObject("user").getString("reputation")));
        users[i] = u;
        // System.out.print(u.toString());
      }
    } catch (JSONException e) {
      e.printStackTrace();
    }
    return users;
  }
  /**
   * Parses BUFFER method parameters for WPS execute xml variables
   *
   * @param lc WFS layer configuration
   * @param json Method parameters and layer info from the front
   * @param baseUrl Url for Geoserver WPS reference input (input FeatureCollection)
   * @return BufferMethodParams parameters for WPS execution
   *     **********************************************************************
   */
  private BufferMethodParams parseBufferParams(
      WFSLayerConfiguration lc, JSONObject json, String baseUrl) throws ServiceException {
    final BufferMethodParams method = new BufferMethodParams();
    method.setMethod(BUFFER);
    //
    try {
      method.setLayer_id(ConversionHelper.getInt(lc.getLayerId(), 0));
      method.setServiceUrl(lc.getURL());
      baseUrl = baseUrl.replace("&", "&amp;");
      method.setHref(baseUrl + String.valueOf(lc.getLayerId()));
      method.setTypeName(lc.getFeatureNamespace() + ":" + lc.getFeatureElement());
      method.setMaxFeatures(String.valueOf(lc.getMaxFeatures()));
      method.setSrsName(lc.getSRSName());
      method.setOutputFormat(DEFAULT_OUTPUT_FORMAT);
      method.setVersion(lc.getWFSVersion());
      method.setXmlns(
          "xmlns:" + lc.getFeatureNamespace() + "=\"" + lc.getFeatureNamespaceURI() + "\"");

      method.setGeom(lc.getGMLGeometryProperty());

      final JSONObject params = json.getJSONObject(JSON_KEY_METHODPARAMS);
      final JSONObject bbox = json.getJSONObject("bbox");
      method.setX_lower(bbox.optString("left"));
      method.setY_lower(bbox.optString("bottom"));
      method.setX_upper(bbox.optString("right"));
      method.setY_upper(bbox.optString("top"));

      method.setDistance(params.optString("distance"));

    } catch (JSONException e) {
      throw new ServiceException("Method parameters missing.");
    }

    return method;
  }
Example #9
0
  public static synchronized boolean handleJsonWithJsonObject(Context context, String response) {
    try {
      ResponseData responseData;
      JSONObject jsonObject = new JSONObject(response);
      String reason = jsonObject.getString("reason");
      String errorCode = jsonObject.getString("error_code");
      if (errorCode.equals("0")) {
        JSONObject result = jsonObject.getJSONObject("result");
        JSONObject data = result.getJSONObject("data");
        JSONObject realtime = data.getJSONObject("realtime");
        RealtimeWeather realtimeWeather = handleResponseOfRealtime(realtime);
        JSONObject life = data.getJSONObject("life");
        LifeData lifeData = handleResponseOfLifeData(life);
        JSONArray weather = data.getJSONArray("weather");
        FutureWeather[] weathers = handleResponseOfFutureWeather(weather);
        JSONObject pm25 = data.getJSONObject("pm25");
        PM25Data pm25Data = handleResponseOfPM25(pm25);
        WeatherData weatherData = new WeatherData(realtimeWeather, lifeData, weathers, pm25Data);
        responseData = new ResponseData(reason, weatherData, errorCode);
      } else {
        responseData = new ResponseData(reason, null, errorCode);
      }
      saveWithSharedPerference(context, responseData);

    } catch (Exception e) {
      e.printStackTrace();
    }
    return false;
  }
 public void testMessageWithFireEvent() throws IOException, JSONException {
   StringWriter stringWriter = new StringWriter();
   PrintWriter printWriter = new PrintWriter(stringWriter);
   ProtocolMessageWriter writer = new JsonMessageWriter(printWriter);
   Display display = new Display();
   Shell shell = new Shell(display);
   Button button = new Button(shell, SWT.PUSH);
   writer.addFireEventPayload(WidgetUtil.getId(button), "selection");
   String widgetId = WidgetUtil.getId(button);
   String actual = stringWriter.getBuffer().toString();
   JSONObject message = new JSONObject(actual + "]}");
   JSONArray widgetArray = message.getJSONArray(IProtocolConstants.MESSAGE_WIDGETS);
   JSONObject widgetObject = widgetArray.getJSONObject(0);
   String type = widgetObject.getString(IProtocolConstants.WIDGETS_TYPE);
   assertEquals(IProtocolConstants.PAYLOAD_FIRE_EVENT, type);
   String actualId = widgetObject.getString(IProtocolConstants.WIDGETS_ID);
   assertEquals(widgetId, actualId);
   JSONObject payload = widgetObject.getJSONObject(IProtocolConstants.WIDGETS_PAYLOAD);
   String actualEvent = payload.getString(IProtocolConstants.KEY_EVENT);
   assertEquals("selection", actualEvent);
   writer.addFireEventPayload(WidgetUtil.getId(button), "focus");
   writer.finish();
   actual = stringWriter.getBuffer().toString();
   message = new JSONObject(actual);
   widgetArray = message.getJSONArray(IProtocolConstants.MESSAGE_WIDGETS);
   widgetObject = widgetArray.getJSONObject(1);
   type = widgetObject.getString(IProtocolConstants.WIDGETS_TYPE);
   assertEquals(IProtocolConstants.PAYLOAD_FIRE_EVENT, type);
   actualId = widgetObject.getString(IProtocolConstants.WIDGETS_ID);
   assertEquals(widgetId, actualId);
   payload = widgetObject.getJSONObject(IProtocolConstants.WIDGETS_PAYLOAD);
   actualEvent = payload.getString(IProtocolConstants.KEY_EVENT);
   assertEquals("focus", actualEvent);
 }
  public void testStreamWithBlock() throws IOException, JSONException {
    StringWriter stringWriter = new StringWriter();
    PrintWriter printWriter = new PrintWriter(stringWriter);
    ProtocolMessageWriter writer = new JsonMessageWriter(printWriter);
    Display display = new Display();
    Shell shell = new Shell(display);
    Button button = new Button(shell, SWT.PUSH);
    writer.appendPayload(
        WidgetUtil.getId(shell), IProtocolConstants.PAYLOAD_CONSTRUCT, "key", "value");
    writer.addConstructPayload(
        WidgetUtil.getId(button),
        WidgetUtil.getId(button.getParent()),
        button.getClass().getName(),
        new String[] {"PUSH"},
        null);
    writer.appendPayload(
        WidgetUtil.getId(button), IProtocolConstants.PAYLOAD_SYNCHRONIZE, "key", "value");
    writer.appendPayload(
        WidgetUtil.getId(button), IProtocolConstants.PAYLOAD_SYNCHRONIZE, "key2", "value");

    writer.finish();
    String actual = stringWriter.getBuffer().toString();
    JSONObject message = new JSONObject(actual);
    JSONArray widgetArray = message.getJSONArray(IProtocolConstants.MESSAGE_WIDGETS);
    JSONObject widgetObject = widgetArray.getJSONObject(1);
    JSONObject payload = widgetObject.getJSONObject(IProtocolConstants.WIDGETS_PAYLOAD);
    String parentId = payload.getString(IProtocolConstants.KEY_PARENT_ID);
    assertEquals(WidgetUtil.getId(shell), parentId);
    widgetObject = widgetArray.getJSONObject(2);
    payload = widgetObject.getJSONObject(IProtocolConstants.WIDGETS_PAYLOAD);
    assertEquals("value", payload.getString("key"));
    assertEquals("value", payload.getString("key2"));
  }
Example #12
0
  public static Long findKFId(String email, Long id) {
    Long kfId = null;
    try {
      final String base_url = "http://oneapm.udesk.com/api/v1/user/view";
      String sign = LoginApi.getSign(email);
      String url = base_url + "?username=" + email + "&sign=" + sign;
      String result = sendGet(url);
      JSONObject object = new JSONObject(result);
      kfId = Long.parseLong(object.getJSONObject("datas").get("id").toString());
      if (kfId != null) {
        InfoDaoImpl.getInstance().updateKf(id, kfId);
      }
      return kfId;
    } catch (Exception e) {

    }
    try {
      final String base_url = "http://oneapm.kf5.com/api/v1/user/add";
      String sign = LoginApi.getSign(email);
      String url = base_url + "?username=" + email + "&sign=" + sign;
      String result = sendGet(url);
      JSONObject object = new JSONObject(result);
      kfId = Long.parseLong(object.getJSONObject("datas").get("id").toString());
      if (kfId != null) {
        InfoDaoImpl.getInstance().updateKf(id, kfId);
      }
      return kfId;
    } catch (Exception e) {
      LOG.error(e.getMessage(), e);
    }
    return null;
  }
Example #13
0
    @Override
    protected String doInBackground(String... params) {
      videos.clear();

      try {
        JSONObject jObject =
            MizLib.getJSONObject(
                "http://gdata.youtube.com/feeds/api/users/TEDtalksDirector/uploads?alt=json&start-index=1&max-results=50");
        JSONObject jdata = jObject.getJSONObject("feed");
        JSONArray aitems = jdata.getJSONArray("entry");

        for (int i = 0; i < aitems.length(); i++) {
          JSONObject item = aitems.getJSONObject(i);
          JSONObject id = item.getJSONObject("id");

          videos.add(
              new WebVideo(
                  item.getJSONObject("title").getString("$t"),
                  id.getString("$t")
                      .substring(
                          id.getString("$t").lastIndexOf("videos/") + 7,
                          id.getString("$t").length()),
                  item.getJSONObject("media$group")
                      .getJSONArray("media$thumbnail")
                      .getJSONObject(0)
                      .getString("url")));
        }
      } catch (Exception e) {
      }

      return null;
    }
Example #14
0
 public void jsonCallback(String url, JSONObject json, AjaxStatus status, String keyPlace) {
   try {
     String price1 =
         json.getJSONObject("result")
             .getJSONArray("Result")
             .getJSONArray(0)
             .getJSONObject(0)
             .getString("Price");
     String price2 =
         json.getJSONObject("result")
             .getJSONArray("Result")
             .getJSONArray(0)
             .getJSONObject(1)
             .getString("Price");
     if (GOS.isRub()) {
       GOS.setPricesRub(keyPlace + "_business", price1 + " \u20BD");
       GOS.setPricesRub(keyPlace + "_standard", price2 + " \u20BD");
     }
     if (GOS.isEur()) {
       GOS.setPricesEur(keyPlace + "_business", "$" + price1);
       GOS.setPricesEur(keyPlace + "_standard", "$" + price2);
     }
     if (GOS.isUsd()) {
       GOS.setPricesUsd(keyPlace + "_business", "$" + price1);
       GOS.setPricesUsd(keyPlace + "_standard", "$" + price2);
     }
     printPrices();
   } catch (JSONException e) {
     e.printStackTrace();
   }
 }
  @Test
  public void testToString() throws Exception {
    ProductBagApi bags = new ProductBagApi(new MockContext());
    bags.addProduct("some bag name", new Product.Builder("product name", "product sku", 1).build());
    bags.addProduct(
        "some bag name", new Product.Builder("product name 2", "product sku 2", 1).build());
    bags.addProduct(
        "some bag name 2", new Product.Builder("product name 3", "product sku 3", 1).build());
    bags.addProduct("some bag name 3", null);
    JSONObject json = new JSONObject(bags.toString());
    assertTrue(json.has("some bag name"));
    JSONObject bag1 = json.getJSONObject("some bag name");
    assertTrue(bag1.has("pl"));
    JSONArray products1 = bag1.getJSONArray("pl");
    assertEquals(2, products1.length());
    JSONObject bag2 = json.getJSONObject("some bag name 2");
    assertTrue(bag2.has("pl"));
    JSONArray products2 = bag2.getJSONArray("pl");
    assertEquals(1, products2.length());

    JSONObject bag3 = json.getJSONObject("some bag name 3");
    assertTrue(bag3.has("pl"));
    JSONArray products3 = bag3.getJSONArray("pl");
    assertEquals(0, products3.length());
  }
Example #16
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);
   }
 }
  @Test
  public void writeJSONWithSelectedFieldsConvertsSolvedStatus() throws ComponentLookupException {
    Map<String, String> map = new LinkedHashMap<String, String>();
    map.put(STATUS_KEY, "1");
    PatientData<String> patientData = new DictionaryPatientData<String>(DATA_NAME, map);
    doReturn(patientData).when(this.patient).getData(DATA_NAME);
    JSONObject json = new JSONObject();
    Collection<String> selectedFields = new LinkedList<>();
    selectedFields.add(STATUS_KEY);

    this.mocker.getComponentUnderTest().writeJSON(this.patient, json, selectedFields);
    Assert.assertEquals(STATUS_SOLVED, json.getJSONObject(DATA_NAME).get("status"));

    map.clear();
    json = new JSONObject();
    map.put(STATUS_KEY, "0");
    patientData = new DictionaryPatientData<>(DATA_NAME, map);
    doReturn(patientData).when(this.patient).getData(DATA_NAME);

    this.mocker.getComponentUnderTest().writeJSON(this.patient, json, selectedFields);
    Assert.assertEquals(STATUS_UNSOLVED, json.getJSONObject(DATA_NAME).get("status"));

    map.clear();
    json = new JSONObject();
    map.put(STATUS_KEY, "solved");
    patientData = new DictionaryPatientData<>(DATA_NAME, map);
    doReturn(patientData).when(this.patient).getData(DATA_NAME);

    this.mocker.getComponentUnderTest().writeJSON(this.patient, json, selectedFields);
    Assert.assertFalse(json.getJSONObject(DATA_NAME).has("status"));
  }
Example #18
0
 /**
  * 我的资料
  *
  * @param string
  * @return
  */
 public static Object getMyData(String string) {
   if (getResultInt(string) == 0) {
     try {
       JSONObject object = new JSONObject(string);
       JSONObject result = object.getJSONObject("result");
       JSONObject data1 = result.getJSONObject("data");
       LoginModel model = new LoginModel();
       model.setHead_photo(data1.getString("head_photo"));
       model.setShop_name(data1.getString("shop_name"));
       model.setContact_person(data1.getString("contact_person"));
       model.setMobile(data1.getString("mobile"));
       model.setAreaframe(data1.getString("areaframe"));
       model.setShop_addr(data1.getString("shop_addr"));
       model.setShopuser_name(data1.getString("shopuser_name"));
       model.setRevenues_code(data1.getString("revenues_code"));
       model.setContact_tel(data1.getString("contact_tel"));
       model.setBusiness_encoding(data1.getString("business_encoding"));
       return model;
     } catch (JSONException e) {
       e.printStackTrace();
     }
     return null;
   } else {
     return getErrorValue(string);
   }
 }
Example #19
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 #20
0
 /**
  * 获取订单数量
  *
  * @param string
  * @return
  */
 public static HashMap<String, String> getOrderNum(String string) {
   if (getResultInt(string) == 0) {
     try {
       JSONObject object = new JSONObject(string);
       JSONObject result = object.getJSONObject("result");
       JSONObject data1 = result.getJSONObject("data");
       JSONObject data2 = data1.getJSONObject("data");
       HashMap<String, String> map = new HashMap<>();
       map.put("TRADE_FINISHED", data2.getString("TRADE_FINISHED"));
       map.put("TRADE_CANCEL", data2.getString("TRADE_CANCEL"));
       map.put("WAIT_APPROVE", data2.getString("WAIT_APPROVE"));
       map.put("DELIVER_GOODS", data2.getString("DELIVER_GOODS"));
       map.put("WAIT_GOODS", data2.getString("WAIT_GOODS"));
       map.put("TRADE_CLOSED", data2.getString("TRADE_CLOSED"));
       map.put("WAIT_CONFRIM", data2.getString("WAIT_CONFRIM"));
       map.put("RECEIVE_GOODS", data2.getString("RECEIVE_GOODS"));
       map.put("AFTERSALES", data2.getString("AFTERSALES"));
       return map;
     } catch (JSONException e) {
       e.printStackTrace();
     }
     return null;
   }
   return null;
 }
	public RedartModel parseRedartModel(String json_object) {

		RedartModel local_model = null;
		try {
			JSONObject jsobj = new JSONObject(json_object);

			ShockedModel shocked = shocked_parser.parseShockedModel(jsobj.getJSONObject("shocked").toString());

			ContentModel content = content_parser.parseContentModel(jsobj.getJSONObject("content").toString());

			ThumbiModel thumbi = thumbi_parser.parseThumbiModel(jsobj.getJSONObject("thumbi").toString());

			PlayerModel player = player_parser.parsePlayerModel(jsobj.getJSONObject("player").toString());

			RuseModel ruse = ruse_parser.parseRuseModel(jsobj.getJSONObject("ruse").toString());

			ArrayList<String> tags = new ArrayList<>();
			JSONArray tags_arr = jsobj.getJSONArray("tags");

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

				tags.add((String) tags_arr.get(i)));

			}

			local_model = new RedartModel(shocked, content, thumbi, jsobj.getString("commentVote"), jsobj.getString("rate"), jsobj.getString("title"), jsobj.getString("uploadedon"), jsobj.getString("id"), player, jsobj.getString("description"), jsobj.getInt("viewCount"), ruse, jsobj.getInt("commentCount"), jsobj.getInt("ratingCount"), jsobj.getInt("favoriteCount"), tagsjsobj.getString("syndicate"), );
		} catch (JSONException e) {
Example #22
0
 /**
  * 新增客户状态审核列表
  *
  * @param string
  * @return
  */
 public static Object getClientsReviewModels(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<ClientsReviewModel> models = new ArrayList<>();
       for (int i = 0; i < data2.length(); i++) {
         JSONObject jsonObject = data2.getJSONObject(i);
         ClientsReviewModel model = new ClientsReviewModel();
         model.setAreaframe(jsonObject.getString("areaframe"));
         model.setContact_person(jsonObject.getString("contact_person"));
         model.setContact_tel(jsonObject.getString("contact_tel"));
         model.setRepairdepot_address(jsonObject.getString("repairdepot_address"));
         model.setRepairdepot_name(jsonObject.getString("repairdepot_name"));
         model.setAppove_status(jsonObject.getInt("appove_status"));
         model.setUser_id(jsonObject.getString("user_id"));
         models.add(model);
       }
       return models;
     } catch (JSONException e) {
       e.printStackTrace();
     }
     return null;
   } else {
     return getErrorValue(string);
   }
 }
Example #23
0
  @Override
  protected void onPostExecute(String result) {

    ArrayList<DataTrackerArtist> trackdata = new ArrayList<DataTrackerArtist>();

    progDialog.dismiss();
    if (result.length() == 0) {
      this.activity.alert("Unable to find track data. Try again later.");
      return;
    }

    try {
      JSONObject respObj = new JSONObject(result);
      JSONObject topTracksObj = respObj.getJSONObject("toptracks");
      JSONArray tracks = topTracksObj.getJSONArray("track");
      for (int i = 0; i < tracks.length(); i++) {
        JSONObject track = tracks.getJSONObject(i);
        String trackname = track.getString("name");
        String trackplaycount = track.getString("playcount");
        JSONObject artistObj = track.getJSONObject("@attr");
        String rank = artistObj.getString("rank");

        trackdata.add(new DataTrackerArtist(trackname, trackplaycount, rank));
      }

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

    this.activity.setTracks(trackdata);
  }
Example #24
0
 /**
  * 授信额度变更列表
  *
  * @param string
  * @return
  */
 public static Object getSearchCreditLineModels(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<SearchCreditLineModel> models = new ArrayList<>();
       for (int i = 0; i < data2.length(); i++) {
         JSONObject jsonObject = data2.getJSONObject(i);
         SearchCreditLineModel model = new SearchCreditLineModel();
         model.setCurrent(jsonObject.getString("current"));
         model.setApply(jsonObject.getString("apply"));
         model.setResult(jsonObject.getString("result"));
         model.setStatus(jsonObject.getString("status"));
         model.setUser_id(jsonObject.getInt("user_id"));
         model.setRepairdepot_name(jsonObject.getString("repairdepot_name"));
         models.add(model);
       }
       return models;
     } catch (JSONException e) {
       e.printStackTrace();
     }
     return null;
   } else {
     return getErrorValue(string);
   }
 }
Example #25
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;
 }
Example #26
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;
 }
 private SheetContent deserializeContent(JSONObject sheetJSON) throws Exception {
   SheetContent toReturn = null;
   JSONObject content = sheetJSON.optJSONObject(WorkSheetSerializationUtils.CONTENT);
   if (content == null) {
     logger.warn(
         "Sheet content not found for sheet ["
             + sheetJSON.getString(WorkSheetSerializationUtils.NAME)
             + "].");
     return null;
   }
   String designer = content.getString(WorkSheetSerializationUtils.DESIGNER);
   if (WorkSheetSerializationUtils.DESIGNER_PIVOT.equals(designer)) {
     toReturn =
         (CrosstabDefinition)
             SerializationManager.deserialize(
                 content.getJSONObject(WorkSheetSerializationUtils.CROSSTABDEFINITION),
                 "application/json",
                 CrosstabDefinition.class);
     ((CrosstabDefinition) toReturn).setStatic(false);
   } else if (WorkSheetSerializationUtils.DESIGNER_STATIC_PIVOT.equals(designer)) {
     toReturn =
         (CrosstabDefinition)
             SerializationManager.deserialize(
                 content.getJSONObject(WorkSheetSerializationUtils.CROSSTABDEFINITION),
                 "application/json",
                 CrosstabDefinition.class);
     ((CrosstabDefinition) toReturn).setStatic(true);
   } else if (WorkSheetSerializationUtils.DESIGNER_TABLE.equals(designer)) {
     toReturn = deserializeTable(content);
   } else {
     toReturn = deserializeChart(content);
   }
   return toReturn;
 }
Example #28
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);
   }
 }
  /**
   * Get the JSON data for the Case Study
   *
   * @return boolean indicates whether the case study data is loaded
   */
  private boolean cacheJSON() {
    if (this.getType().equals("LOCAL")) {
      try {
        JSONobj = (new JSONObject(this.loadJSONFromAsset(this.getLocation())));
        Iterator<String> iter = JSONobj.keys();
        this.id = iter.next();

        JSONobj = JSONobj.getJSONObject(this.id);
      } catch (JSONException e) {
        e.printStackTrace();
      }
      return true;
    } else if (this.getType().equals("DISK")) {
      try {
        JSONobj = (new JSONObject(this.loadJSONFromStorage(this.getLocation())));
        Iterator<String> iter = JSONobj.keys();
        this.id = iter.next();

        JSONobj = JSONobj.getJSONObject(this.id);
      } catch (JSONException e) {
        e.printStackTrace();
      }
      return true;
    } else {
      return false;
    }
  }
  private OpenGraphObject buildOpenGraphObject(JSONObject actionParams) throws JSONException {
    JSONObject jsonObject = actionParams.getJSONObject("object");

    OpenGraphObject object = OpenGraphObject.Factory.createForPost(jsonObject.getString("type"));
    object.setTitle(jsonObject.getString("title"));
    object.setDescription(jsonObject.getString("description"));

    if (jsonObject.has("url")) {
      object.setUrl(jsonObject.getString("url"));
    }

    object.setImageUrls(Arrays.asList(jsonObject.getString("image")));

    JSONObject dataObject = jsonObject.getJSONObject("data");

    @SuppressWarnings("unchecked")
    Iterator<String> keys = (Iterator<String>) dataObject.keys();

    while (keys.hasNext()) {
      String key = keys.next();

      object.getData().setProperty(key, dataObject.get(key));
    }

    return object;
  }