这是我的json
:
{
"message":"Success",
"method":"getList",
"values": [
{
"_id":"2"
}
]
}
有两个模型类:
public class ModelList {
@SerializedName("message")
public String MESSAGE;
@SerializedName("method")
public String METHOD;
public List<ModelValue> modelValues;
}
和
public class ModelValue {
@SerializedName("_id")
public String ARTIST_ID;
}
这是我在Activity中的代码。
ModelList response;
response = gson.fromJson(jsonToStringFromAssetFolder("twitter_search.json", JsonParsingActivity.this),
ModelArtistList.class);
Toast.makeText(this, response.MESSAGE, Toast.LENGTH_SHORT).show();
List<ModelValue> results = response.modelValues;
for (ModelValue result : results) {
Toast.makeText(this, result._ID, Toast.LENGTH_SHORT).show();
Log.e("log_tag","result.fromUser"+result._ID);
}
我在NullPointerException
List<ModelValue> results = response.modelValues;
答案 0 :(得分:1)
我认为您需要ModelList
课程:@SerializedName("values")
modelValues
public class ModelList {
@SerializedName("message")
public String MESSAGE;
@SerializedName("method")
public String METHOD;
@SerializedName("values")
public List<ModelValue> modelValues;
}