晚上好
我在 Android Studio 中学习 Android 开发,我是原始 C# 开发人员 我现在正在将 json 解析为我的 android 应用程序
在我的 Events.java 中使用以下代码
public static class HttpRequestTask extends AsyncTask<Void, Void, Events> {
@Override
protected Events doInBackground(Void... params) {
try {
String url = "http://example.com/Example.ashx?Onderdeel=Feeds&AuthToken=" + Core.AuthToken;
Log.e("Ophalen Events", url);
RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
Events events = restTemplate.getForObject(url, Events.class);
// Log.e("EVENTS:", events.getContent());
return events;
} catch (Exception e) {
Log.e("MainActivity", e.getMessage(), e);
}
return null;
}
}
我在我的 onCreateView 中调用这段代码 喜欢
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_item_detail, container, false);
new Events.HttpRequestTask().execute();
return rootView;
}
问题是我想返回对象/类事件
喜欢事件 e = Events.HttpRequestTask().execute(); 并且比 e = 我填充的对象。
自从我是新手以来,有人有任何提示或想法吗:) 非常喜欢
问候, 斯特凡
最佳答案
调用 execute() 将返回 AsyncTask 本身,您需要在其之上调用 get() 方法。
Events e = new HttpRequestTask().execute().get();
关于java - JSON Spring 框架 Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31753211/