开发工具后台返回的是utf-8编码的数组,真机返回的则是ascii的JSON字符串,怎么处理?
发布于 4 年前 作者 nhan 12320 次浏览 来自 问答

开发工具返回的:{errno: 0, message: “”, data: Array(1)}

  1. accountidnull
  2. actionnull
  3. areanull
  4. back_img""
  5. commission"0"
  6. createtime"1587566664"
  7. credit"0.00"
  8. displayorder"0"
  9. id"1"
  10. keyword""
  11. lat" "
  12. linkmen"总机"
  13. linkway""
  14. lng" "
  15. parent_accountidnull
  16. pic"images/0/2021/05/UruJzh823UTezeq52QEqRURURyUjJa.png"
  17. pid"0"
  18. province"广东省"
  19. qq" "
  20. region_qr""
  21. region_type"4"
  22. rid"0"
  23. service_url""
  24. stamp""
  25. status"1"
  26. thumb""
  27. uid"1"
  28. uniacid"4"
  29. url""
  30. villageidnull
  31. yybcommunityidnull
  32. yybstatus"33"
  33. zoneIdnull

真机调试返回的:{“errno”:0,“message”:"",“data”:[{“id”:“1”,“uniacid”:“4”,“linkmen”:"\u603b\u673a",“linkway”:"",“lng”:" “,“lat”:” “,“pid”:“0”,“url”:”",“thumb”:"",“pic”:“images\/1\/2020\/04\/2263323556162116.jpg”,“province”:"\u5e7f\u4e1c\u7701",“qq”:" “,“rid”:“0”,“keyword”:”",“commission”:“0”,“status”:“1”,“area”:null,“stamp”:"",“credit”:“0.00”,“action”:null,“yybstatus”:“33”,“yybcommunityid”:null,“accountid”:null,“villageid”:null,“zoneId”:null,“parent_accountid”:null,“back_img”:"",“displayorder”:“0”,“service_url”:"",“region_type”:“4”,“region_qr”:"",“uid”:“1”,“createtime”:“1587566664”}]}

2 回复

我说的接口,你发出来这么多小程序代码也没用啊

wx.request({

	'url': url,

	'data': option.data ? option.data : {},

	'header': option.header ? option.header : {},

	'method': option.method ? option.method : 'GET',

	'header': {

		'content-type': 'application/x-www-form-urlencoded'

	},

	'success': function (response) {

		wx.hideNavigationBarLoading();

		if (response.data.errno) {

			if (response.data.errno == '41009') {

				wx.setStorageSync('userInfo', '');

				util.getUserInfo(function () {

					util.request(option)

				});

				return;

			} else {

				if (option.fail && typeof option.fail == 'function') {

					option.fail(response);

				} else {

					if (response.data.message) {

						if (response.data.data != null && response.data.data.redirect) {

							var redirect = response.data.data.redirect;

						} else {

							var redirect = '';

						}

						app.util.message(response.data.message, redirect, 'error');

					}

				}

				return;

			}

            } else {

			if (option.success && typeof option.success == 'function') {

				option.success(response);

			}

			//写入缓存,减少HTTP请求,并且如果网络异常可以读取缓存数据

			if (option.cachetime) {

				var cachedata = { 'data': response.data, 'expire': timestamp + option.cachetime \* 1000 };

				wx.setStorageSync(cachekey, cachedata);

			}

		}

	},

	'fail': function (response) {

		wx.hideNavigationBarLoading();

		//wx.hideLoading();

 

		//如果请求失败,尝试从缓存中读取数据

		var md5 = require('md5.js');

		var cachekey = md5(url);

		var cachedata = wx.getStorageSync(cachekey);

		if (cachedata && cachedata.data) {

			if (option.success && typeof option.success == 'function') {

				option.success(cachedata);

			}

			console.log('failreadcache:' + url);

			return true;

		} else {

			if (option.fail && typeof option.fail == 'function') {

				option.fail(response);

			}

		}

	},

	'complete': function (response) {

		// wx.hideNavigationBarLoading();

		// wx.hideLoading();

		if (option.complete && typeof option.complete == 'function') {

			option.complete(response);

		}

	}

});

还不时伴有 cmdId 10005 errCode 1的白屏出现

回到顶部