简体   繁体   English

com.android.volley.parse错误java.lang.string类型的org.json.jsonexception值无法在Android Volley中转换为jsonArray

[英]com.android.volley.parse error org.json.jsonexception value of type java.lang.string cannot be converted to jsonArray in Android Volley

When I run this program I get this error . 当我运行该程序时,出现此错误。 I don't know how to solve . 我不知道该怎么解决。 Help me finding it Please. 请帮我找到它。

This is my json_encode php code api. 这是我的json_encode php代码api。

  $i=0;
  while ($row = $result->fetch_assoc())
  {
   $array[$i]=array(
        "news_id" => $row["news_id"], 
        "news_title" => $row["news_title"], 
        "news_abstract" => $row["news_abstract"], 
        "news_content" => $row["news_content"], 
        "news_date" => $row["news_date"], 
        "news_link" => $row["news_link"], 
        "news_image_link" => $row["news_image_link"], 
        "sources_name" => $row["sources_name"], 
        "category_name" => $row["category_name"],
        "news_visible" => $row["news_visible"]
    );
    $i++;
  }
    $json=json_encode($array, JSON_HEX_TAG|JSON_HEX_APOS);

and my JsonArrayRequest of Android Volley JsonArrayRequest. 和我的Android Volley JsonArrayRequest的JsonArrayRequest。

JsonArrayRequest newsRequest = new JsonArrayRequest( Url.getUrlJson(), new  Response.Listener<JSONArray>(){
        @Override
        public void onResponse( JSONArray response ){
            Log.d( TAG, response.toString() );
            hidePDialog();

            // Parsing json
            for( int i = 0; i < response.length(); i++ ){
                try{
                    JSONObject obj = response.getJSONObject( i );
                    News news = new News();
                     if( "1".equals( obj.getString( "news_visible" )) ){

                        news.setNews_id( obj.getString( "news_id" ) );
                        news.setNews_title( obj.getString( "news_title" ) );
                        news.setNews_abstract( obj.getString( "news_abstract" ) );
                        news.setNews_content( obj.getString( "news_content" ) );
                        news.setNews_date( obj.getString( "news_date" ) );
                        news.setNews_link( obj.getString( "news_link" ) );
                        news.setNews_image_link( obj.getString( "news_image_link" ));
                        news.setSources_name( obj.getString( "sources_name" ) );
                        news.setCategory_name( obj.getString( "category_name" ) );
                    }
                    newsList.add( news );
                }
                catch( JSONException e ){
                    e.printStackTrace();
                }

Content Type 内容类型

<?PHP
header('Content-Type: application/json');

See Returning JSON from a PHP script . 请参阅从PHP脚本返回JSON

Byte Order Marker 字节顺序标记

PHP is prone to return a BOM at the beginning of the response, when the .php file or any of its include s have UTF-8 character encoding. .php文件或其中的任何include UTF-8字符编码时, .php倾向于在响应开始时返回BOM

For more information, see this W3C answer and section UTF-8 BOM in this post . 有关更多信息,请参见W3C答案和本文中的UTF-8 BOM部分。

One suggested way to prevent PHP from prepending a BOM is to change the character set of your php file(s) from UTF-8 to ASCII or ISO-8859-15. 一种建议的防止PHP附加BOM的方法是将php文件的字符集从UTF-8更改为ASCII或ISO-8859-15。

您得到的响应是一个字符串,您正在尝试将其关联到jsonArray

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 com.android.volley.parseerror org.json.json异常值类型为java.lang.String的无法转换为JSONObject - com.android.volley.parseerror org.json.jsonexception value yes of type java.lang.String cannot be converted to JSONObject android错误org.json.JSONException:值 - android error org.json.JSONException: Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject 解析数据org.json.JSONException时出错:类型java.lang.String的值无法转换为JSONArray - Error Parsing Data org.json.JSONException: Value of type java.lang.String cannot be converted to JSONArray com.android.volley.ParseError: org.json.JSONException: Value 0 of type java.lang.Integer cannot be converted to JSONObject - com.android.volley.ParseError: org.json.JSONException: Value 0 of type java.lang.Integer cannot be converted to JSONObject volley.parsererror:org.json.JSONException:类型java.lang.string的值br不能转换为JSONObject - volley.parsererror:org.json.JSONException: value br of type java.lang.string cannot be converted to JSONObject Volley 的 JsonObjectRequest 给出“org.json.JSONException: Value - Volley's JsonObjectRequest gives "org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject" exception Volley的JsonObjectRequest提供了“ org.json.JSONException:值 - Volley's JsonObjectRequest gives “org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject” exception Volley库W / System.err:org.json.JSONException:类型为java.lang.String的Value Connected无法转换为JSONObject - Volley library W/System.err: org.json.JSONException: Value Connected of type java.lang.String cannot be converted to JSONObject org.json.JSONException值java.lang.String类型的连接无法转换为JSONArray - org.json.JSONException value Connection of type java.lang.String cannot be converted to JSONArray org.json.JSONException:类型为java.lang.String成功时的值0无法转换为JSONArray - org.json.JSONException: Value 0 at success of type java.lang.String cannot be converted to JSONArray
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM