我正在以 JSON 的形式从我的 PHP MYSQL 数据库中获取一条停止记录,并且在 Android 中接收 JSON 时出现的问题是,在 91 次停止后 JSON 对象不再获取进一步的记录,我有 400 多个数据库记录,请任何人帮忙为什么 JSON 对象不获取所有记录?
安卓代码
public class MainActivity extends ActionBarActivity {
private static final String TAG_SUCCESS = "success";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new DBProcessing().execute();
}
public class DBProcessing extends AsyncTask<String,Object,Object>
{
JSONObject json = new JSONObject();
String result=null;
@Override
protected String doInBackground(String... args) {
// DatabaseHandler db = new DatabaseHandler(MainActivity.this);
String getURL = "http://192.168.1.51:80/StopViewApi/index.php";
String GetStopid="";
String Getstopname="";
String Getstoplatitude="";
String Getstoplongitude="";
List<NameValuePair> pair = new ArrayList<>();
pair.add(new BasicNameValuePair("Stop_id", GetStopid));
pair.add(new BasicNameValuePair("Stop_name", Getstopname));
pair.add(new BasicNameValuePair("Stop_latitude", Getstoplatitude));
pair.add(new BasicNameValuePair("Stop_longitude", Getstoplongitude));
json = JSONParser.makeHttpRequest(getURL,"POST", pair);
// Log.d("Create Response", json.toString());
JSONObject jObject=null;
try {
// JSONArray jArray = new JSONArray(result);
JSONObject json_data=null;
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
JSONArray array = new JSONArray(json.toString());
for(int i=0;i<array.length();i++) {
System.out.println("Stop_id:"+array.getJSONObject(i).getString("Stop_id"));
System.out.println("Stop_name:"+array.getJSONObject(i).getString("Stop_name"));
System.out.println("Stop_latitude:"+array.getJSONObject(i).getString("Stop_latitude"));
System.out.println("Stop_longitude:"+array.getJSONObject(i).getString("Stop_longitude"));
}
Log.d("Record Found!", json.getString(TAG_SUCCESS));
// Log.d("Stop record:!", json.toString());
//Log.i("Stop_name:", Getstopname);
//Log.i("Stop_latitude",Getstoplatitude);
//Log.i("Stop_longitude",Getstoplongitude);
}
else if (success==0){
Log.d("Record Failure!", json.getString(TAG_SUCCESS));
return json.getString(TAG_SUCCESS);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
}
}
JSON 网址
"success":1,"data":[["1","Pirwadhai Mor","33.615707","72.994629"],["2","Mandi Mor","33.634666","73.032005"],["3","Police Line","33.652676","73.013039"]
最佳答案
您尝试过 Google Gson API ?它可能是代替 JSON 的不错选择,并且您可以清楚地了解解析器或请求是否有问题。
有一个很好且简单的例子here .
关于Android JSON 对象丢失了 URL 中的剩余数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30289212/