国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

webman 如何解析JSON數(shù)據(jù)包?

小杰
public funciton a{
    retunr json(['code'=>0,'msg'=>'ok']);
}
new $res = a;

1.如何取得a函數(shù)返回json數(shù)據(jù)的code,msg?

public function b(Request $request)
{
    // 創(chuàng)建一個對象
    $response = response();

    // 設置cookie
    $response->cookie('foo', 'value');

    new $res = a;

    // 設置要返回的數(shù)據(jù)
    $response->withBody($res);
    return $response;
}

2.$res的數(shù)據(jù)在ajax中無法解析出來?

2602 1 0
1個回答

Tinywan

返回的json數(shù)據(jù)前端要解析才可以使用的

let res = JSON.parse(e.data);
console.log(res)
  • 小杰 2021-12-02

    贊,感謝! 我原來項目中大量的json()返回數(shù)據(jù),在webman框架的php業(yè)務邏輯中,如何能解析json得到里面的數(shù)據(jù)?

  • Tinywan 2021-12-02

    你前端就是上面那樣子解析的呀

  • 小杰 2021-12-02

    public funciton a{
    retunr json(['code'=>0,'msg'=>'ok']);
    }
    new $res = a;
    if($res->code ==0){
    //業(yè)務
    }

    或者用json_decode()解析成數(shù)組,使用$res['code']來獲取, webman中的json對象,不能用這種方法解析。

  • Tinywan 2021-12-03

    怎么就不行了,我寫的都已經(jīng)上線運行了,https://www.webman.tinywan.cn/

年代過于久遠,無法發(fā)表回答
??