zoukankan      html  css  js  c++  java
  • 微信小程序入门教程(一)API接口数据记录

    今天测试用小程序调用API接口,发现有些数据打印都是对象,怎么全部打印详细点来

    小程序代码:

      httpsearch: function (name, offset, type, cb) {
        wx.request({
          url: 'https://www.tinywan.com/api/wechat/songsSearch',
          data: {
            name: name,
            offset: offset,
            limit: 20,
            type: type
          },
          method: 'GET',
          success: function (res) {var arr = res.data.playlist.item;
            for (var x in arr){
              console.log(x);
              console.log(arr[x]);
            }
          }
        })
      }

    服务端代码:

        public function songsSearch()
        {
            $name = input('param.name');
            $offset = input('param.offset');
            $limit = input('param.limit');
            $type = input('param.type');
            $curlReq = curl_request('http://stream.aliyun.com/api/search/get/',[
                's'=>$name,
                'limit'=>$limit,
                'type'=>$type,
                'offset'=>$offset,
            ]);
            $arrRes = json_decode($curlReq,true);
            $newArr = [];
            foreach ($arrRes['result']['songs'] as $key=>$val){
                $newArr[] = [
                    'id'=>$val['id'],
                    'name'=>$val['name'],
                    'creatorId'=>$val['artists'][0]['id'],
                    'creator'=>$val['artists'][0]['name'],
                    'img1v1Url'=>$val['artists'][0]['img1v1Url'],
                ];
            }
            $res = [
                'code' => 200,
                'msg' => 'success',
                'playlist' =>[
                    'item'=> $newArr,
                    'songCount'=> $arrRes['result']['songCount'],
                ]
            ];
            return json($res);
        }

    打印结果

  • 相关阅读:
    nosql----redis持久化详解
    linux下发送邮件
    自动化运维工具----ansiable安装与配置
    nginx----统计网站访问量
    机试指南第二章-经典入门-排序例题自解
    机试指南第二章-经典入门-排序模板
    Theano入门
    OpenJudge 4120 硬币
    OpenJudge 1088 滑雪
    OpenJudge 4152 最佳加法表达式
  • 原文地址:https://www.cnblogs.com/tinywan/p/8350005.html
Copyright © 2011-2022 走看看