0

http fetch を介して JSON をデコード/解析していますが、Android では null の結果が得られますが、ブラウザーでは有効な JSON 形式である次の結果が得られます。

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

ここで、配列は、mysql db に中規模のブロブとして保存する double 値の長いリストです。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>

私のアンドロイド 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