我可以将这个复杂的json转换为java类吗? 我正在使用GSON来解析JSON数据。
http://api.feedzilla.com/v1/categories/26/articles.json
这样的事情:
Parsing a complex Json Object using GSON in Java
编辑:我在JAVA中使用了GSON的这个例子复杂JSON对象
这是我的课文:
public class Article {
public String publish_date;
public String source;
public String source_url;
public String summary;
public String title;
public String url;
}
DataStorage类:
public class DataStorage {
public static List<Article> article;
}
MyActivity类:
public class MyActivity extends Activity {
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AsyncHttpClient httpClient = new AsyncHttpClient();
httpClient.get("http://api.feedzilla.com/v1/categories/26/articles.json", null,
new JsonHttpResponseHandler()
{
@Override
public void onSuccess(int statusCode, Header[] headers, JSONArray response)
{
Log.d("HTTP_RESPONSE", response.toString());
Gson myGson = new Gson();
DataStorage ac = myGson.fromJson(response.toString(), DataStorage.class);
Log.d("HTTP_RESPONSE", response.toString());
//listView.setAdapter(new Adapter(getApplicationContext()));
}
}
);
}
}
我编译后在logcat中显示,为什么?
12-30 16:22:20.044 1156-1156/com.example.Articles W/JsonHttpResponseHandler﹕ onSuccess(int, Header[], JSONObject) was not overriden, but callback was received
答案 0 :(得分:1)
使用JSON美化器(如http://jsonformatter.curiousconcept.com/),这样您就可以更好地了解其中的内容。然后,创建类,如下所示:
class article {
String publish_date;
String title;
...