Android错误JSON:类stdclass的catchable致命错误对象无法转换为字符串

时间:2014-07-14 22:36:46

标签: php android json

我是android编程的新手,所以我从我的虚拟设备中获取“类stdclass的catcble致命错误对象无法转换为字符串”的错误。 php类中的错误行如下。谢谢你的回答。

PHP代码:

$friendlocs= $db->getFriendsLocations($useremail);


$a=array();
$b=array();



if ($res){
while ($row = mysql_fetch_array($friendlocs))
    {
            //$b["id"] = $data[$j]->id;

            $b["f_name"] = "_";
            $b["f_email"] = $row[0];
            $b["f_lat"] = $row[1];
            $b["f_lon"] = $row[2];
            $b["f_time"] = $row[3];
            $b["f_timezone"] = $row[4];
            $b["f_synctime"] = $row[5];
            $b["f_friend_status"] = $row[6];


            array_push($a,$b);

    }
}




 print json_encode($a);

PHP功能:

    public function getFriendsLocations($user_email) {
    // birden fazla row döndüreceği için ANY ifadesi kullanılarak birleştiriliyor.
        $result = mysql_query("select user_email,and_loc_lat, and_loc_long, and_loc_time, and_loc_timezone, and_sync_time, user_loc_status FROM tbl_currentlocs WHERE user_email = ANY (select DISTINCT friend_email FROM tbl_friendship WHERE user_email = '$user_email')");
    return $result;
}

Android代码:

                    try {
                            JSONArray arr = new JSONArray(response);
                            System.out.println("try başladı");
                            System.out.println(arr.length());
                            for(int i=0; i<arr.length();i++){
                                System.out.println("for başladı");
                                JSONObject obj = (JSONObject)arr.get(i);
                                System.out.println(obj.get("f_name"));
                                System.out.println(obj.get("f_email"));
                                System.out.println(obj.get("f_lat"));
                                System.out.println(obj.get("f_lon"));
                                System.out.println(obj.get("f_time"));
                                System.out.println(obj.get("f_timezone"));
                                System.out.println(obj.get("f_synctime"));
                                System.out.println(obj.get("f_friend_status"));

                                     friendDb.updateFriendLocSyncStatus(obj.get("f_name").toString(), obj.get("f_email").toString(), obj.get("f_lat").toString(), obj.get("f_lon").toString(), obj.get("f_time").toString(), obj.get("f_timezone").toString(), obj.get("f_friend_status").toString(), obj.get("f_synctime").toString() );
                            }
                            Toast.makeText(getApplicationContext(), "Friend Location Sync completed!", Toast.LENGTH_LONG).show();
                        } catch (JSONException e) {
                            // TODO Auto-generated catch block
                            Toast.makeText(getApplicationContext(), "Error Occured [Server's JSON response might be invalid]!", Toast.LENGTH_LONG).show();
                            e.printStackTrace();
                        }
                    }

0 个答案:

没有答案