서버에서 데이터를 수신해야한다는 하나의 응용 프로그램을 개발 중이며 성공적으로 데이터를 읽습니다. 여기에 내가 서버 코드에서 데이터를받을 AsyncTask, 쓴 및 AsyncTask에서 내 활동, 여기에 하나만 데이터를 보낼 내 json 개체를 3 objects.i AsyncTask 있지만 3 점점 개체를 얻을 수 있습니다. 활동에안드로이드에서 Json Object를 파싱 하시겠습니까?
내 AsyncTask를
public class ReceivingLatLongAsync extends AsyncTask<Void, Void, Void> {
private ProgressDialog pDialog;
Context mContext;
JSONArray jsonArryDetails=null;
public static final String DETAILS = "locations";
public static final String LAT = "lat";
public static final String LNG = "lng";
public static final String ADDRESS = "address";
public static final String CTIME = "ctime";
private String lat1;
private String lng1;
private String address1;
private String time1;
public ReceivingLatLongAsync(Context context){
this.mContext = context;
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
pDialog = new ProgressDialog(mContext);
pDialog.setMessage("Please wait...");
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
ServiceHandler serviceHandler= new ServiceHandler();
String jSonString = `serviceHandler.makeServiceCall
(TrafficConstants.RECIEVE_LATLON_POL_URL, ServiceHandler.POST);`
Log.e("Response: ", "> " + jSonString);
if(jSonString != null){
try {
JSONObject jsonObject = new JSONObject(jSonString);
jsonArryDetails = jsonObject.getJSONArray(DETAILS);
for(int i = 0;i<jsonArryDetails.length();i++){
JSONObject mapDetails =
jsonArryDetails.getJSONObject(0);
lat1 = mapDetails.getString(LAT);
lng1 = mapDetails.getString(LNG);
address1 = mapDetails.getString(ADDRESS);
time1 = mapDetails.getString(CTIME);
Log.e("ADDRESS1", address1);
Log.e("TIME2",time1);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
pDialog.dismiss();
Intent intent = new Intent(mContext,GetLatLongForTPActivity.class);
intent.putExtra("LAT", lat1);
intent.putExtra("LNG", lng1);
intent.putExtra("ADDRESS", address1);
intent.putExtra("time",time1);
mContext.startActivity(intent);
}
}
내 activty
public class GetLatLongForTPActivity extends FragmentActivity
implements LocationListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_get_lat_long_for_tp);
timeEdit = (EditText)findViewById(R.id.timeId);
submitBtn = (Button)findViewById(R.id.subId);
Intent intent = getIntent();
String anotherLAT=intent.getStringExtra("LAT");
String anotherLNG=intent.getStringExtra("LNG");
Log.e(" NEW LATLONG",anotherLAT);
}
시도의 _startActivity (의도) _ _mContext.startActivity (의도)되지; _ –
당신이 구현해야하는 목적을 가진 하나 개의 클래스를 생성, 객체의 하나 개의 배열을 보내고 당신의 배열을 보내기 위해, 그 배열을 보내야합니다' –
을 parcelable' 구문 분석 옵션의 경우 Gson을 시도하십시오. http://stackoverflow.com/questions/21480634/unable-to-loop-through-dynamic-json-string-recursively-in-android/21480997#21480997 – user2450263