• Laravel JsonResponse数组获取


    有一个JsonResponse数据的格式如下:

    object(IlluminateHttpJsonResponse)[474]
      protected 'data' => string '{"code":200,"message":"u6210u529f","data":{"file_name":"b3c8622cc85a5783b6b39e6c998f8c1e.jpg","file_path":"b3/c8/b3c8622cc85a5783b6b39e6c998f8c1e.jpg","file_size":290576,"url":"https://quxuexi-pub.qfq.me/b3/c8/b3c8622cc85a5783b6b39e6c998f8c1e.jpg","original_url":"/tmp/phpUVwzdV"}}' (length=292)
      protected 'callback' => null
      protected 'encodingOptions' => int 0
      public 'headers' => 
        object(SymfonyComponentHttpFoundationResponseHeaderBag)[476]
          protected 'computedCacheControl' => 
            array (size=2)
              'no-cache' => boolean true
              'private' => boolean true
          protected 'cookies' => 
            array (size=0)
              empty
          protected 'headerNames' => 
            array (size=3)
              'cache-control' => string 'Cache-Control' (length=13)
              'date' => string 'Date' (length=4)
              'content-type' => string 'Content-Type' (length=12)
          protected 'headers' => 
            array (size=3)
              'cache-control' => 
                array (size=1)
                  ...
              'date' => 
                array (size=1)
                  ...
              'content-type' => 
                array (size=1)
                  ...
          protected 'cacheControl' => 
            array (size=0)
              empty
      protected 'content' => string '{"code":200,"message":"u6210u529f","data":{"file_name":"b3c8622cc85a5783b6b39e6c998f8c1e.jpg","file_path":"b3/c8/b3c8622cc85a5783b6b39e6c998f8c1e.jpg","file_size":290576,"url":"https://quxuexi-pub.qfq.me/b3/c8/b3c8622cc85a5783b6b39e6c998f8c1e.jpg","original_url":"/tmp/phpUVwzdV"}}' (length=292)
      protected 'version' => string '1.0' (length=3)
      protected 'statusCode' => int 200
      protected 'statusText' => string 'OK' (length=2)
      protected 'charset' => null
      public 'original' => 
        array (size=3)
          'code' => int 200
          'message' => string '鎴愬姛' (length=6)
          'data' => 
            array (size=5)
              'file_name' => string 'b3c8622cc85a5783b6b39e6c998f8c1e.jpg' (length=36)
              'file_path' => string 'b3/c8/b3c8622cc85a5783b6b39e6c998f8c1e.jpg' (length=42)
              'file_size' => int 290576
              'url' => string 'https://quxuexi-pub.qfq.me/b3/c8/b3c8622cc85a5783b6b39e6c998f8c1e.jpg' (length=69)
              'original_url' => string '/tmp/phpUVwzdV' (length=14)
      public 'exception' => null

    想要获取其中的data数据,然后就直接:

    $result['data'];

    最后发现这是不可以的,正确的方法如下:

    $jsonArray = $result->getData(true);
  • 相关阅读:
    人名币转大写
    Http协议与TCP协议简单理解
    unity3d常用属性汇总
    ConcurrentHashMap的key value不能为null,map可以?
    一个线程池中的线程异常了,那么线程池会怎么处理这个线程?
    Dubbo负载均衡算法
    [LeetCode] 240. 搜索二维矩阵 II ☆☆☆(二分查找类似)
    [LeetCode] 74. 搜索二维矩阵 ☆☆☆(二分查找)
    Maven中的dependencyManagement 意义
    深入理解maven构建生命周期和各种plugin插件
  • 原文地址:https://www.cnblogs.com/cjjjj/p/9991989.html
Copyright © 2020-2023  润新知