ようなコードを書くことができ
http://www.json.org/を記載されています。あなたのJSONと
例:
-----------------------------------com.example.Datum.java-----------------------------------
package com.example;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Datum {
@SerializedName("address")
@Expose
private String address;
@SerializedName("balance")
@Expose
private Integer balance;
@SerializedName("nonce")
@Expose
private Object nonce;
@SerializedName("code")
@Expose
private String code;
@SerializedName("name")
@Expose
private Object name;
@SerializedName("storage")
@Expose
private Object storage;
@SerializedName("firstSeen")
@Expose
private String firstSeen;
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public Integer getBalance() {
return balance;
}
public void setBalance(Integer balance) {
this.balance = balance;
}
public Object getNonce() {
return nonce;
}
public void setNonce(Object nonce) {
this.nonce = nonce;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public Object getName() {
return name;
}
public void setName(Object name) {
this.name = name;
}
public Object getStorage() {
return storage;
}
public void setStorage(Object storage) {
this.storage = storage;
}
public String getFirstSeen() {
return firstSeen;
}
public void setFirstSeen(String firstSeen) {
this.firstSeen = firstSeen;
}
}
-----------------------------------com.example.Example.java-----------------------------------
package com.example;
import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Example {
@SerializedName("status")
@Expose
private Integer status;
@SerializedName("data")
@Expose
private List<Datum> data = null;
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public List<Datum> getData() {
return data;
}
public void setData(List<Datum> data) {
this.data = data;
}
}
あなたが機能してjsonStringからオブジェクトを取得します後:
// Deserialize to single object.
public Example deserializeFromJson(String jsonString) {
Gson gson = new Gson();
Example myClass = gson.fromJson(jsonString, Example.class);
return myClass;
}
そして、あなたはあなたのオブジェクト内のすべてのものを得ることができます。
私はそれがあなたの問題を助けることを願っています!それはあなたがJSONオブジェクトにアクセスし、そのパスでトークンを見つけることができますように私はNewtonSoftとまったく同じように、私がまさに必要だ https://github.com/json-path/JsonPath
:
[Gsonを使用してJSONをHashMapに変換するにはどうすればよいですか?](https://stackoverflow.com/questions/2779251/how-can-i-convert-json-to-a-hashmap-using- gson) – logcat