public void test_for_xiayucai2012() throws Exception {
    String text = "{\"date\":\"0000-00-00 00:00:00\"}";
    JSONObject json = JSON.parseObject(text);
    Date date = json.getObject("date", Date.class);

    Assert.assertEquals(
        new SimpleDateFormat(JSON.DEFAULT_DATE_FORMAT).parse(json.getString("date")), date);
  }
Пример #2
0
 public VideoMessage(byte[] data) {
   String jsonStr = new String(data);
   if (!TextUtils.isEmpty(jsonStr)) {
     JSONObject jsonObject = JSON.parseObject(jsonStr);
     if (!jsonObject.isEmpty()) {
       String videoUrl = jsonObject.getString("videoUrl");
       if (!TextUtils.isEmpty(videoUrl)) {
         this.remoteVideoUri = Uri.parse(videoUrl);
       }
       if (this.getRemoteVideoUri() != null
           && this.getRemoteVideoUri().getScheme() != null
           && !this.getRemoteVideoUri().getScheme().equals("http")) {
         this.localVideoUri = this.remoteVideoUri;
       }
       base64ImgContent = jsonObject.getString("imgContent");
       this.isUploadExp = true;
       this.setUserInfo(jsonObject.getObject("user", UserInfo.class));
     }
   }
 }
  @Override
  public Result<T> parse(String response) {
    Result<T> result = new Result<T>();
    try {
      JSONObject baseObject = JSON.parseObject(response);
      if (!baseObject.getBooleanValue("success")) {
        result.setMsg(baseObject.getString("message"));
      } else {
        Class<T> klass = Helper.generateType(getClass());
        if (klass == null) throw new Exception();

        T t = baseObject.getObject(mKey, klass);
        result.setStatus(Result.SUCCESS);
        result.setResult(t);
        return result;
      }
    } catch (Exception e) {
      e.printStackTrace();
      result.setMsg(Net.ERR_PARSE_MSG);
    }

    result.setStatus(Result.ERROR);
    return result;
  }