【问题标题】:How to parse json using gson ?如何使用 gson 解析 json?
【发布时间】:2017-06-10 16:37:12
【问题描述】:

我怎样才能得到时间或文字 这个json http://www.mocky.io/v2/58889af52600007c1d966456 有人可以帮助我吗???

【问题讨论】:

标签: java android android-studio


【解决方案1】:
public String parse(String jsonLine) {
  JsonElement jelement = new JsonParser().parse(jsonLine);
  JsonObject  jobject = jelement.getAsJsonObject();
  jobject = jobject.getAsJsonObject("data");
  JsonArray jarray = jobject.getAsJsonArray("translations");
  jobject = jarray.get(0).getAsJsonObject();
  String result = jobject.get("translatedText").toString();
  return result;
} //jsonLine refer to json

【讨论】:

  • OP 要求使用 GSON 的解决方案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-02-12
  • 2012-01-02
  • 1970-01-01
  • 2014-05-10
  • 2015-07-10
  • 2012-01-12
  • 1970-01-01
相关资源
最近更新 更多