I've done a long search before posting, none of solutions work for me. I'm creating an Android application, using JSON and PHP;

在发布之前我做了很长时间的搜索,没有一个解决方案适合我。我正在使用JSON和PHP创建一个Android应用程序;

PHP

/**
*
LOT OF USELESS THING
*
*/
//Attributing values of $OUTPUT

$q=mysql_query($query);

if (!$q) 
   die(mysql_error()); // You'll be notified if there's any syntax error in your query.  

$OUTPUT = array(array());           
if ($q && @mysql_num_rows($q) > 0) {
    // looping through all results
    // products node

    while($e=@mysql_fetch_assoc($q)){
        if (!empty($e['title'])){
        $u = Array();
        $u['id'] = mb_convert_encoding($e['id'], 'UTF-8');
        $u['title'] = mb_convert_encoding($e['title'], 'UTF-8');
        $u['location_search_text'] =  mb_convert_encoding($e['location_search_text'], 'UTF-8');
        $OUTPUT[] = $u;}
        //echo "<br>************<br>";*/

            //$OUTPUT[] = $e;
    }
}
print(json_encode($OUTPUT));

Now, this is the output of json:

现在,这是json的输出:

[[],{"id":"796","title":"ANSEJ ORAN \/Agence de Soutien \u00e0 l'Emploi des Jeunes d'Oran","locat ...etc

If you see, there's a []; an empty array, which of course causes me problem in Java, when parsing data with

如果你看,有一个[];一个空数组,当用数据解析数据时,这当然会导致我在Java中遇到问题

JSONArray jArray = new JSONArray(result);

Occuring me a JSONExcpetion:

给我一个JSONExcpetion:

Error parsing data org.json.JSONException: Value [] at 0 of type org.json.JSONArray cannot be converted to JSONObject

1 个解决方案

#1


1

Not $OUTPUT = array(array()); - this create empty array inside

不是$ OUTPUT = array(array()); - 这里面创建空数组

But $OUTPUT = array();

但$ OUTPUT = array();

更多相关文章

  1. PHP XAMPP配置PHP环境和Apache80端口被占用解决方案
  2. 如何在不更改其键值的情况下删除数组的第一个元素?
  3. 以完整二叉树,数组格式获取所有节点
  4. php 写一个算法,查寻数组里第一个大于某数的值。
  5. 插入PHP数组作为MYSQL列
  6. php把从数据库读取出来的数据存放到数组里
  7. 在key/value的基础上将数组分组到另一个数组中
  8. MySQL / PHP:将整行推入关联数组,_without_命名每个单元格
  9. 在ajax中接收php多维数组。

随机推荐

  1. Android View和ViewGroup的关系
  2. Android Studio 1.5 opencv开发
  3. Android(安卓)快捷键
  4. Android Java执行Shell命令
  5. Android构建工具Gradle知识1
  6. Android USB/MTP相关实现
  7. android 界面布局 很好的一篇总结 【转】
  8. android面试题整理(2)
  9. 配置Qt Creator for Android
  10. Android Intent个人介绍