データの解析エラーorg.json.JSONException:タイプjava.lang.Stringの値<brをJSONArrayに変換できません

Samvid kulkarni

ユーザーが検索するデータを入力し、アプリケーションがそれをサーバーに送信し、サーバーが検索結果をクライアントに送り返すアプリケーションを作成しています。

エラーが発生し、それが何を意味するのか理解できません。サーバーから正確な結果を取得しています。

ここにアプリケーションからの私のネットワークコードがあり、ここに完全なコードへのリンクがあります

     public class GetDatafromDB_Searchresult {
            String response1 ;


            public String getDataFromDB() {
 httpclient = new DefaultHttpClient();
                    httppost = new HttpPost("http://192.168.0.106/test/search.php"); // make sure the url is correct.
                    //add your data
                    nameValuePairs = new ArrayList<NameValuePair>();
                    // Always use the same variable name for posting i.e the android side variable name and php side variable name should be similar,
                    nameValuePairs.add(new BasicNameValuePair("carat1", strcarat1.toString().trim()));
                    nameValuePairs.add(new BasicNameValuePair("carat2", strcarat2.toString().trim()));
                    nameValuePairs.add(new BasicNameValuePair("carat1", strcolor1.toString().trim()));
                    nameValuePairs.add(new BasicNameValuePair("carat2", strcolor2.toString().trim()));
                    nameValuePairs.add(new BasicNameValuePair("clarity1", strclarity1.toString().trim()));
                    nameValuePairs.add(new BasicNameValuePair("clarity2", strclarity2.toString().trim()));
                    nameValuePairs.add(new BasicNameValuePair("cut1", strcut1.toString().trim()));
                    nameValuePairs.add(new BasicNameValuePair("cut2", strcut2.toString().trim()));
                    nameValuePairs.add(new BasicNameValuePair("shape1", strshape1.toString().trim()));
                    nameValuePairs.add(new BasicNameValuePair("shape2", strshape2.toString().trim()));
                    nameValuePairs.add(new BasicNameValuePair("stones", strstone.toString().trim()));


                    // $Edittext_value = $_POST['Edittext_value'];

                        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                        //Execute HTTP Post Request


                try {
                        response = httpclient.execute(httppost);
                    HttpEntity entity= response.getEntity();
                    {
                        if(entity!=null)
                        {
                            entity.consumeContent();
                        }
                    }

                    ResponseHandler<String> responseHandler = new BasicResponseHandler();
                     response1 = httpclient.execute(httppost, responseHandler);
                    System.out.println("Response : " + response1);

                } catch (Exception e) {
                    e.printStackTrace();
                    System.out.println("Exception : " + e.getMessage());

                }


                return response1.trim();

            }
        }

これが私のサーバーサイドコードです

<?php
$hostname_localhost ="localhost";
$database_localhost ="testdb";
$username_localhost ="root";
$password_localhost ="";
$localhost = mysql_connect($hostname_localhost,$username_localhost,$password_localhost)
or
trigger_error(mysql_error(),E_USER_ERROR);

 mysql_select_db($database_localhost, $localhost);

$carat1 = $_POST['carat1'];
$carat2 = $_POST['carat2'];
$clarity1 = $_POST['clarity1'];
$clarity2 = $_POST['clarity2'];
$color1 = $_POST['color1'];
$color2 = $_POST['color2'];
$cut1 = $_POST['cut1'];
$cut2 = $_POST['cut2'];
$shape1 = $_POST['shape1'];
$shape2 = $_POST['shape2'];
$stones = $_POST['stones'];

$query_search ="Select * from search1 where carats Between '$carat1' and '$carat2' and 
color = '$color1' or color =  '$color2' and cut = '$cut1' or cut = '$cut2' and shape = '$shape1' or shape =  '$shape2' and stone ='$stones' ";

$query_exec = mysql_query($query_search) or die(mysql_error());


    while($row=mysql_fetch_assoc($query_exec))
            $json_output[]=$row;
      echo json_encode($json_output);

    mysql_close();

?>

また、echo json_encode($ json_output);を変更しました。印刷する(json_encode($ json_output)); それでも出力に問題はありません

これがlogcatからの私の出力です。

06-06 12:10:19.825    1237-1566/com.diamond.traders I/System.out﹕ <font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
06-06 12:10:19.825    1237-1566/com.diamond.traders I/System.out﹕ <tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: color1 in C:\wamp\www\test\search.php on line <i>16</i></th></tr>
06-06 12:10:19.825    1237-1566/com.diamond.traders I/System.out﹕ <tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
06-06 12:10:19.825    1237-1566/com.diamond.traders I/System.out﹕ <tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
06-06 12:10:19.825    1237-1566/com.diamond.traders I/System.out﹕ <tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0010</td><td bgcolor='#eeeeec' align='right'>147496</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='C:\wamp\www\test\search.php' bgcolor='#eeeeec'>..\search.php<b>:</b>0</td></tr>
06-06 12:10:19.825    1237-1566/com.diamond.traders I/System.out﹕ </table></font>
06-06 12:10:19.825    1237-1566/com.diamond.traders I/System.out﹕ <br />
06-06 12:10:19.825    1237-1566/com.diamond.traders I/System.out﹕ <font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
06-06 12:10:19.825    1237-1566/com.diamond.traders I/System.out﹕ <tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: color2 in C:\wamp\www\test\search.php on line <i>17</i></th></tr>
06-06 12:10:19.825    1237-1566/com.diamond.traders I/System.out﹕ <tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
06-06 12:10:19.825    1237-1566/com.diamond.traders I/System.out﹕ <tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
06-06 12:10:19.825    1237-1566/com.diamond.traders I/System.out﹕ <tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0010</td><td bgcolor='#eeeeec' align='right'>147496</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='C:\wamp\www\test\search.php' bgcolor='#eeeeec'>..\search.php<b>:</b>0</td></tr>
06-06 12:10:19.825    1237-1566/com.diamond.traders I/System.out﹕ </table></font>
06-06 12:10:19.825    1237-1566/com.diamond.traders I/System.out﹕ [{"id":"4","product_code":"4","shape":"Asscher","pair":"jgj","carats":"1.8","color":"G","clarity":"VS2","service":"iuhi","polish":"hiihi","symetric":"hih","tables":"ihi","measurments":"hi","flourscne":"hi","description":"ih","certificated":"hjgj","ccode":"hjgj","cut":"Signature Ideal","total":"iuhiu","file":"hiuhih","stone":"Single"}]
06-06 12:10:19.825    1237-1566/com.diamond.traders I/System.out﹕ <br />
06-06 12:10:19.825    1237-1566/com.diamond.traders I/System.out﹕ <font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
06-06 12:10:19.825    1237-1566/com.diamond.traders I/System.out﹕ <tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: color1 in C:\wamp\www\test\search.php on line <i>16</i></th></tr>
06-06 12:10:19.825    1237-1566/com.diamond.traders I/System.out﹕ <tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
06-06 12:10:19.825    1237-1566/com.diamond.traders I/System.out﹕ <tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
06-06 12:10:19.825    1237-1566/com.diamond.traders I/System.out﹕ <tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0010</td><td bgcolor='#eeeeec' align='right'>147496</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='C:\wamp\www\test\search.php' bgcolor='#eeeeec'>..\search.php<b>:</b>0</td></tr>
06-06 12:10:19.825    1237-1566/com.diamond.traders I/System.out﹕ </table></font>
06-06 12:10:19.825    1237-1566/com.diamond.traders I/System.out﹕ <br />
06-06 12:10:19.825    1237-1566/com.diamond.traders I/System.out﹕ <font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
06-06 12:10:19.825    1237-1566/com.diamond.traders I/System.out﹕ <tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: color2 in C:\wamp\www\test\search.php on line <i>17</i></th></tr>
06-06 12:10:19.825    1237-1566/com.diamond.traders I/System.out﹕ <tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
06-06 12:10:19.825    1237-1566/com.diamond.traders I/System.out﹕ <tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
06-06 12:10:19.825    1237-1566/com.diamond.traders I/System.out﹕ <tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0010</td><td bgcolor='#eeeeec' align='right'>147496</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='C:\wamp\www\test\search.php' bgcolor='#eeeeec'>..\search.php<b>:</b>0</td></tr>
06-06 12:10:19.825    1237-1566/com.diamond.traders I/System.out﹕ </table></font>
06-06 12:10:19.825    1237-1566/com.diamond.traders I/System.out﹕ [{"id":"4","product_code":"4","shape":"Asscher","pair":"jgj","carats":"1.8","color":"G","clarity":"VS2","service":"iuhi","polish":"hiihi","symetric":"hih","tables":"ihi","measurments":"hi","flourscne":"hi","description":"ih","certificated":"hjgj","ccode":"hjgj","cut":"Signature Ideal","total":"iuhiu","file":"hiuhih","stone":"Single"}]
06-06 12:10:19.825    1237-1237/com.diamond.traders E/log_tag﹕ Error parsing data org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONArray
Rod_Algonquin

データベースからHTMLコードが返されますが、データベースからステートメントの結果を変更する必要があります。

問題:あなたはこのphpパラメータからあなたにcolorパラメータを入れるのを忘れましたNameValuePairs

    $color1 = $_POST['color1'];
$color2 = $_POST['color2'];

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

Related 関連記事

ホットタグ

アーカイブ