[英]koush/ion getting json in in textview
我试图理解Koushi-ion的代码,以便可以从网站获取json数据并将其输入到列表视图中。 现在,我仅使用textview对其进行测试。
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.testview);
test = (TextView)findViewById(R.id.testview1);
Ion.with(getApplication(), "mywebsite")
.asJsonObject()
.setCallback(new FutureCallback<JsonObject>() {
@Override
public void onCompleted(Exception e, JsonObject result) {
// do stuff with the result or error
inputTest = result.getAsString();
test.setText(inputTest);
}
我收到logcat错误:unsupportedoperationException: JsonObject at com.google.Gson.JsonElement.getAsString(JsonElement java:191);
用离子不是那么简单吗?
您使用的Gson错误。 如果要将json作为字符串,则只需使用result.toString即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.