我正在尝试使用 gson 反序列化 JSON 对象中的数据。我在 1)设计课程时遇到了麻烦。2) 从内部列表对象中获取空对象。
这是 JSON 对象的示例
{
"spatialReference" : {
"wkid" : 102113
},
"candidates" : [
{
"address" : "202 S Van Ness Ave, San Francisco, CA, 94110",
"location" : {
"x" : -13627444.2697,
"y" : 4546249.2471000031
},
"score" : 85.969999999999999,
"attributes" : {
"Loc_name" : "US_RoofTop",
"Score" : 85.969999999999999,
"Match_addr" : "505 S Van Ness Ave, San Francisco, CA, 94110",
"House" : "505",
"Side" : "R",
"PreDir" : "S",
"PreType" : "",
"StreetName" : …Run Code Online (Sandbox Code Playgroud) 我遇到了一个问题.我需要使用asynctask来检索JSON数据,在移动到程序的下一部分之前我需要这些数据.但是,当我使用AsyncTask的get()方法时,在看到数据显示之前,我有5到8秒的黑屏.我想在数据检索期间显示进度对话框,但由于黑屏,我无法执行此操作.有没有办法放入另一个线程?这是一些代码
的AsyncTask
public class DataResponse extends AsyncTask<String, Integer, Data> {
AdverData delegate;
Data datas= new Data();
Reader reader;
Context myContext;
ProgressDialog dialog;
String temp1;
public DataResponse(Context appcontext) {
myContext=appcontext;
}
@Override
protected void onPreExecute()
{
dialog= new ProgressDialog(myContext);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.setCancelable(false);
dialog.setMessage("Retrieving...");
dialog.show();
};
@Override
protected Data doInBackground(String... params) {
temp1=params[0];
try
{
InputStream source = retrieveStream(temp1);
reader = new InputStreamReader(source);
}
catch (Exception e)
{
e.printStackTrace();
}
Gson gson= new Gson();
datas= gson.fromJson(reader, Data.class);
return datas;
}
@Override
protected void …Run Code Online (Sandbox Code Playgroud)