[英]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.