douxian3170 2013-04-06 10:35
浏览 30

通过json格式的php获取mysql向量到Android jsonarray返回null

I am decoding/parsing JSON over http fetch and on android I get null results, while on a browser I get the following, which is valid JSON format:

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

where the array is a long list of double values I store as a medium blob in a mysql db. In android, I get this no matter what I try:

[{"KEY":""}]

I've tried changing between httpget and httppost, and looked at may other posts on SO and tried their suggestions, to no avail. Here is the 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>

My android HttpPost or HttpGet look more or less like:

<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>

Any suggestions on what I am doing wrong?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
    • ¥20 易康econgnition精度验证
    • ¥15 msix packaging tool打包问题
    • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致