微信小程序入门教程(一)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); }

打印结果

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM