如何将扫码获取的string数据转为json形式?

小程序 文章 2022-03-07 11:20 378 0 全屏看文

AI助手支持GPT4.0

如何将扫码获取的string数据转为json形式?How to convert the string data obtained by scanning the code into json format?

如何将扫码获取的string数据转为json形式?
wx.scanCode({            scanType:['qrCode'],            onlyFromCameratrue,//设置只能用相机扫描            success(res){              var data=res.result;  console.log(data);})如何将这个data数据转为json形式并通过wx.navigateTo({                url'/pages/info/info',                events: {                  // 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据                  acceptDataFromOpenedPagefunction(data{                    console.log(data)                  },                  someEventfunction(data{                    console.log(data)                  }                },                successfunction(res{                  // 通过eventChannel向被打开页面传送数据                  res.eventChannel.emit('acceptDataFromOpenerPage', { data'数据' })                }              })发往另一也页面调用显示

wx. Scancode ({scantype: ['qrcode '], onlyfromcamera: true, / / set that you can only scan with the camera {success (RES) {var data = result. Result; console. Log (data);}) How to convert this data into JSON form and pass it through Wx Navigateto ({URL: '/ pages / Info / Info', events: {/ / add a listener for the specified event to get the data transferred from the opened page to the current page {                    console.log(data)                  },                  someEvent: function(data) {                    console.log(data)                  }                }, Success: function (RES) {/ / transfer data to the opened page through eventchannel res.eventchannel.emit ('acceptdatafromopenerpage ', {data:' data '}) }}) send to another page to call the display

回答:

社交恐怖分z:

如果是字符串里面是json可以用JSON.parse()

八九:

百度一下,你就知道

小黎:

你都拿到数据了转json干嘛

-EOF-

AI助手支持GPT4.0