我正在使用AsyncTask来解析服务器上的JSON。但是,当我运行我的应用程序时,我遇到了问题。在我的logcat中,我的JSON看起来很好,但之后会出现错误消息android Error parsing data org.json.JSONException: End of input at character 0 of
。我已经尝试过一些来自论坛的建议,但我还没有找到解决这个问题的最佳方法。在这里我的代码:
@Override
protected String doInBackground(String... arg0) {
// TODO Auto-generated method stub
List<NameValuePair> params = new ArrayList<NameValuePair>();
JSONObject json = jParser.makeHttpRequest(url_level_detaildatamerchant, "GET", params);
Log.d("Get List :", json.toString());
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
data = json.getJSONArray(TAG_DATA);
for (int i=0; i<data.length(); i++) {
JSONObject c = data.getJSONObject(i);
Pk_Merchant_ID = c.getString(TAG_Pk_Merchant_ID);
Fk_Ms_DataLevel2_ID = c.getString(TAG_Fk_Ms_DataLevel2_ID);
Fk_Ms_City_ID = c.getString(TAG_Fk_Ms_City_ID);
Fk_Ms_Sales_ID_CreatedBy = c.getString(TAG_Fk_Ms_Sales_ID_CreatedBy);
Fk_Ms_Sales_ID_LastUpdateBy = c.getString(TAG_Fk_Ms_Sales_ID_LastUpdateBy);
CreatedDated = c.getString(TAG_CreatedDated);
LastUpdateDated = c.getString(TAG_LastUpdateDated);
Descriptions = c.getString(TAG_Descriptions);
Address = c.getString(TAG_Address);
Telpon = c.getString(TAG_Telpon);
Handphone = c.getString(TAG_Handphone);
BB_PIN = c.getString(TAG_BB_PIN);
email = c.getString(TAG_email);
Longitude = c.getString(TAG_Longitude);
Latitude = c.getString(TAG_Latitude);
Path_PhotoProfile = c.getString(TAG_Path_PhotoProfile);
Is_Deleted = c.getString(TAG_Is_Deleted);
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_Pk_Merchant_ID, Pk_Merchant_ID);
map.put(TAG_Fk_Ms_DataLevel2_ID, Fk_Ms_DataLevel2_ID);
map.put(TAG_Fk_Ms_City_ID, Fk_Ms_City_ID);
map.put(TAG_Fk_Ms_Sales_ID_CreatedBy, Fk_Ms_Sales_ID_CreatedBy);
map.put(TAG_Fk_Ms_Sales_ID_LastUpdateBy, Fk_Ms_Sales_ID_LastUpdateBy);
map.put(TAG_CreatedDated, CreatedDated);
map.put(TAG_LastUpdateDated, LastUpdateDated);
map.put(TAG_Descriptions, Descriptions);
map.put(TAG_Address, Address);
map.put(TAG_Telpon, Telpon);
map.put(TAG_Handphone, Handphone);
map.put(TAG_BB_PIN, BB_PIN);
map.put(TAG_email, email);
map.put(TAG_Longitude, Longitude);
map.put(TAG_Latitude, Latitude);
map.put(TAG_Path_PhotoProfile, Path_PhotoProfile);
map.put(TAG_Is_Deleted, Is_Deleted);
listData.add(map);
}
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
Log.d("Error", e.toString());
}
return null;
}
这是我的php:
<?php
$response = array();
$dsn='sqlserver';
$username='street';
$password='keymaker';
$koneksi= odbc_connect($dsn,$username,$password);
if (isset($_POST['Fk_Ms_DataLevel2_ID'])) {
$Fk_Ms_DataLevel2_ID = $_POST['Fk_Ms_DataLevel2_ID'];
$query = "select * from Ms_Merchant where Fk_Ms_DataLevel2_ID = '$Fk_Ms_DataLevel2_ID' ";
$result = odbc_exec($koneksi, $query);
$response ["Ms_Merchant"] = array();
WHILE ($row = odbc_fetch_array($result)) {
$Ms_Merchant = array();
$Ms_Merchant["Pk_Merchant_ID"] = $row ["Pk_Merchant_ID"];
$Ms_Merchant["Fk_Ms_DataLevel2_ID"] = $row ["Fk_Ms_DataLevel2_ID"];
$Ms_Merchant["Fk_Ms_City_ID"] = $row ["Fk_Ms_City_ID"];
$Ms_Merchant["Fk_Ms_Sales_ID_CreatedBy"] = $row ["Fk_Ms_Sales_ID_CreatedBy"];
$Ms_Merchant["Fk_Ms_Sales_ID_LastUpdateBy"] = $row ["Fk_Ms_Sales_ID_LastUpdateBy"];
$Ms_Merchant["CreatedDated"] = $row ["CreatedDated"];
$Ms_Merchant["LastUpdateDated"] = $row ["LastUpdateDated"];
$Ms_Merchant["Descriptions"] = $row ["Descriptions"];
$Ms_Merchant["Address"] = $row ["Address"];
$Ms_Merchant["Telpon"] = $row ["Telpon"];
$Ms_Merchant["Handphone"] = $row ["Handphone"];
$Ms_Merchant["BB_PIN"] = $row ["BB_PIN"];
$Ms_Merchant["email"] = $row ["email"];
$Ms_Merchant["Longitude"] = $row ["Longitude"];
$Ms_Merchant["Latitude"] = $row ["Latitude"];
$Ms_Merchant["Path_PhotoProfile"] = $row ["Path_PhotoProfile"];
$Ms_Merchant["Is_Deleted"] = $row ["Is_Deleted"];
array_push($response["Ms_Merchant"], $Ms_Merchant);
}
$response["success"] = 1;
echo json_encode($response);
}
odbc_close($koneksi);
?>
我需要你所有的帮助。谢谢你的进步。