我想收到JSON数组并将其保存到SQLite数据库中?我采取的步骤如下:
共有四列。
try {
// 1. create HttpClient
HttpClient httpclient = new DefaultHttpClient();
// 2. make POST request to the given URL
HttpPost httpPost = new HttpPost( "http://192.168.1.7/sql.php");
//TotalRecord=jsonarray.toString();
StringEntity se = new StringEntity(TotalRecord);
abc=true;
// 6. set httpPost Entity
httpPost.setEntity(se);
使用这些列我想将它们内部的数据接收到JSON数组中,在PHP中实现这一点的任何方法?
邮政结构是:
Cursor res = myDB.getAllData();
if (res.getCount() == 0) {
showMessage("error", "nothing to disply");
return;
}
JSONArray jsonArray = new JSONArray();
//JSONObject jsonObject=new JSONObject();
StringBuffer stringBuffer = new StringBuffer();
while (res.moveToNext()) {// Converted whole sqlite database in Json
JSONObject jsonObject = new JSONObject();
String id = "";
String name = "";
String surname = "";
String marks = "";
id = String.valueOf(stringBuffer.append(res.getString(0)));
name = String.valueOf(stringBuffer.append(res.getString(1)));
surname = String.valueOf(stringBuffer.append(res.getString(0)));
marks = String.valueOf(stringBuffer.append(res.getString(0)));
try {
jsonObject.accumulate("ID", id);
jsonObject.accumulate("Name", name);
jsonObject.accumulate("SurName", surname);
jsonObject.accumulate("Marks", marks);
jsonArray.put(jsonObject);
} catch (JSONException e) {
e.printStackTrace();
}
TotalRecord = jsonArray.toString();