相关疑难解决方法(0)

如何在PHP中将数组转换为对象?

我怎样才能将这样的数组转换为对象?

    [128] => Array
        (
            [status] => Figure A.
 Facebook's horizontal scrollbars showing up on a 1024x768 screen resolution.
        )

    [129] => Array
        (
            [status] => The other day at work, I had some spare time
        )

)

php arrays casting object

329
推荐指数
21
解决办法
63万
查看次数

将JSON发布到Laravel

我正在尝试向Jaravel发送json的帖子请求.请求在服务器上收到,但是当我尝试访问属性时,我得到: "试图获取非对象的属性".在客户端我正在使用angularjs.

角度:

$http.post($rootScope.globals.basePath+"login/handleAjax",{"id" : obj.values[0].id,"profileUrl" : obj.values[0].publicProfileUrl}).success(function(data){
             console.log("got success!",data);
         });
Run Code Online (Sandbox Code Playgroud)

laravel:

class LoginController extends BaseController {
/*User logs in to linkedin and sends his id through ajax to this function*/
public function handle_ajax() {
    $data = Input::all();
    *//Clockwork is just a debugging extension I'm using*
    Clockwork::info($data->id); **//"Trying to get property of non-object".**
}
Run Code Online (Sandbox Code Playgroud)

注意:我可以在Fiddler中看到发送的JSON是有效的,并且它到达控制器+方法(http 200).

帖子请求本身(如Fiddler所见)

Headers: 
Accept: application/json, text/plain, */*
...
Text View:
{"id":"my id","profileUrl":"http://www.linkedin.com/pub/yoel-blum/51/373/76"}
Run Code Online (Sandbox Code Playgroud)

php laravel angularjs

34
推荐指数
3
解决办法
7万
查看次数

标签 统计

php ×2

angularjs ×1

arrays ×1

casting ×1

laravel ×1

object ×1