0

我正在通过 http fetch 解码/解析 JSON,在 android 上我得到空结果,而在浏览器上我得到以下内容,这是有效的 JSON 格式:

[
    {
        "KEY": "-2.71208569845,-1.46780473499, ..."
    }
]

其中数组是一个长长的 double 值列表,我在 mysql db 中存储为中等 blob。在android中,无论我尝试什么,我都会得到这个:

[{"KEY":""}]

我尝试在 httpget 和 httppost 之间进行更改,并查看了 SO 上的其他帖子并尝试了他们的建议,但无济于事。这是PHP:

<snip>
mysql_query('SET CHARACTER SET utf8');
$result=mysql_query("SELECT avgfftspectrum FROM `TremCamTbl` WHERE 
             email='".$_REQUEST['email']."'
             ORDER BY subjectid DESC LIMIT  1");

if (mysql_num_rows($result) > 0) {
    //$response["KEY"] = array(); 
    while ($row = mysql_fetch_assoc($result)) {
        $fftdata[] =  array_map('utf8_encode', $row);
        /*$data = $row["avgfftspectrum"];  I have also tried these two lines
        **array_push($response["KEY"], $data); */
    }
    echo json_encode($fftdata);
} 
<snip>

我的 android HttpPost 或 HttpGet 看起来或多或少像:

<snip>
String paramString = URLEncodedUtils.format(nameValuePairs, "utf-8");
HttpPost httpPost  = new HttpPost(WebConstants.getCloudavgfftUrl()+"?"+paramString);
Log.i(TAG, ""+WebConstants.getCloudavgfftUrl()+"?"+paramString);
try {
    httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    String responseBody = httpClient.execute(httpPost,responseHandler);
    Log.i(TAG, ""+responseBody.length());

    // Parse
    JSONArray jArray = new JSONArray(responseBody);
    Log.i(TAG, ""+jArray.length());
    Log.i(TAG, ""+jArray.toString());
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
} catch (ClientProtocolException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
} catch (JSONException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
<snip>

关于我做错了什么有什么建议吗?

4

0 回答 0