这是我的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;
}
这是我在活动中的代码。
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;