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