小程序json解析

小程序json解析_第1张图片

emmm好烦这个json解析 老是解不通,它传来的值是这样的 

{
	"resultcode":"200",
	"reason":"SUCCESSED!",
	"result":[
		{
			"1":{
				"variety":"Au100g",
				"latestpri":"268.50",
				"openpri":"269.02",
				"maxpri":"269.62",
				"minpri":"268.50",
				"limit":"-0.37%",
				"yespri":"269.50",
				"totalvol":"306.00",
				"time":"2018-07-12 15:04:49"
			},
			"2":{
				"variety":"Au(T+N1)",
				"latestpri":"--",
				"openpri":"--",
				"maxpri":"--",
				"minpri":"--",
				"limit":"--",
				"yespri":"278.25",
				"totalvol":"--",
				"time":"2018-07-11 20:00:00"
			},
			"3":{
				"variety":"Au(T+D)",
				"latestpri":"268.01",
				"openpri":"269.13",
				"maxpri":"269.38",
				"minpri":"267.96",
				"limit":"-0.40%",
				"yespri":"269.08",
				"totalvol":"40132.00",
				"time":"2018-07-12 15:07:36"
			},
			"4":{
				"variety":"Au99.99",
				"latestpri":"268.10",
				"openpri":"269.40",
				"maxpri":"269.40",
				"minpri":"268.10",
				"limit":"-0.33%",
				"yespri":"269.00",
				"totalvol":"92509.00",
				"time":"2018-07-12 15:07:23"
			},
			"5":{
				"variety":"Au99.95",
				"latestpri":"268.10",
				"openpri":"268.65",
				"maxpri":"268.65",
				"minpri":"268.10",
				"limit":"-0.33%",
				"yespri":"269.00",
				"totalvol":"360.00",
				"time":"2018-07-12 15:04:29"
			},
			"6":{
				"variety":"Au50g",
				"latestpri":"--",
				"openpri":"--",
				"maxpri":"--",
				"minpri":"--",
				"limit":"--",
				"yespri":"255.00",
				"totalvol":"--",
				"time":"2018-07-11 20:00:00"
			},
			"7":{
				"variety":"Ag99.99",
				"latestpri":"--",
				"openpri":"--",
				"maxpri":"--",
				"minpri":"--",
				"limit":"--",
				"yespri":"3700.00",
				"totalvol":"--",
				"time":"2018-07-11 20:00:00"
			},
			"8":{
				"variety":"Ag(T+D)",
				"latestpri":"3649.00",
				"openpri":"3655.00",
				"maxpri":"3663.00",
				"minpri":"3642.00",
				"limit":"-0.19%",
				"yespri":"3656.00",
				"totalvol":"2616764.00",
				"time":"2018-07-12 15:07:37"
			},
			"9":{
				"variety":"Au(T+N2)",
				"latestpri":"271.85",
				"openpri":"273.70",
				"maxpri":"273.85",
				"minpri":"271.85",
				"limit":"-0.46%",
				"yespri":"273.10",
				"totalvol":"8912.00",
				"time":"2018-07-12 14:55:09"
			},
			"10":{
				"variety":"Pt99.95",
				"latestpri":"194.00",
				"openpri":"193.60",
				"maxpri":"194.00",
				"minpri":"193.60",
				"limit":"-0.59%",
				"yespri":"195.16",
				"totalvol":"30.00",
				"time":"2018-07-12 15:06:17"
			},
			"11":{
				"variety":"AU995",
				"latestpri":"--",
				"openpri":"--",
				"maxpri":"--",
				"minpri":"--",
				"limit":"--",
				"yespri":"271.60",
				"totalvol":"--",
				"time":"2018-07-11 20:00:00"
			},
			"12":{
				"variety":"AU99.99",
				"latestpri":"268.10",
				"openpri":"269.40",
				"maxpri":"269.40",
				"minpri":"268.10",
				"limit":"-0.33%",
				"yespri":"269.00",
				"totalvol":"925092.00",
				"time":"2018-07-12 15:07:23"
			},
			"13":{
				"variety":"MAUTD",
				"latestpri":"268.10",
				"openpri":"269.05",
				"maxpri":"269.36",
				"minpri":"268.03",
				"limit":"-0.33%",
				"yespri":"269.00",
				"totalvol":"21778.00",
				"time":"2018-07-12 15:07:37"
			},
			"14":{
				"variety":"IAU99.99",
				"latestpri":"267.70",
				"openpri":"268.40",
				"maxpri":"268.40",
				"minpri":"267.70",
				"limit":"-0.42%",
				"yespri":"268.84",
				"totalvol":"18020.00",
				"time":"2018-07-12 15:07:19"
			},
			"15":{
				"variety":"IAU100G",
				"latestpri":"--",
				"openpri":"--",
				"maxpri":"--",
				"minpri":"--",
				"limit":"--",
				"yespri":"269.00",
				"totalvol":"--",
				"time":"2018-07-11 20:00:00"
			},
			"16":{
				"variety":"IAU99.5",
				"latestpri":"--",
				"openpri":"--",
				"maxpri":"--",
				"minpri":"--",
				"limit":"--",
				"yespri":"237.80",
				"totalvol":"--",
				"time":"2018-07-11 20:00:00"
			}
		}
	],
	"error_code":0
}

最后就发现很简单根本不用管他几层 直接上去就行

gold.js

Page({
 
  onLoad: function() {
    var that = this;
    
    wx.request({
      url: 'http://web.juhe.cn:8080/finance/gold/shgold?key=自己去申请',
      header: {
        'content-type': 'application/json'
      },
      success: function(res) {
        console.log(res.data)
        that.setData({
          goldData: res.data.result[0],
           
        })
          
      }
    })
  }
})
< text class= "title" >黄金数据 text >

< block wx:for= "{{goldData}}" wx:key= "this" >
< view class= "gold" >
< view class= "variety" >|品种:{{item.variety}} view >
< view class= "latestpri" >|最新价:{{item.latestpri}} view >
< view class= "openpri" >|开盘价:{{item.openpri}} view >
< view class= "maxpri" >|最高价:{{item.maxpri}} view >
< view class= "minpri" >|最低价:{{item.minpri}} view >
< view class= "limit" >|涨跌幅:{{item.limit}} view >
< view class= "yespri" >|昨收价:{{item.yespri}} view >
< view class= "totalvol" >|总成交量:{{item.totalvol}} view >
< view class= "time" >|更新时间:{{item.time}} view >
< view class= 'dLine' >-------------------------------- view >
view >

block >


我感觉应该是result里多了个{}所以要标个[0],emmmm 应该是固定格式且记下

你可能感兴趣的:(微信小程序)