Arrays Js-如何解析整数数组对象数据
我在数组对象中有一个响应数据 这里是我的回复代码:Arrays Js-如何解析整数数组对象数据,arrays,parsing,vuejs2,integer,Arrays,Parsing,Vuejs2,Integer,我在数组对象中有一个响应数据 这里是我的回复代码: { "data": [ { "id": 7, "product_name": "iPad", "rating": "4.00" }, { "id": 2, "product_name": "iPhone", "rating": "3.00" }, { "id": 8, "product_name": "iP
{
"data": [
{
"id": 7,
"product_name": "iPad",
"rating": "4.00"
},
{
"id": 2,
"product_name": "iPhone",
"rating": "3.00"
},
{
"id": 8,
"product_name": "iPod",
"rating": "7.00"
},
{
"id": 4,
"product_name": "iMac",
"rating": "9.00"
}
],
"status": 200,
"error": 0
}
然后我尝试映射数组对象,将数据“rating”解析为整数,这里是我的axios代码:
getCustomerType: function(store) {
this.loading = true
let headers = {
Authorization: 'Bearer ' + window.accessToken
}
axios({
method: 'GET',
url: baseApi(this.selectedStore.url_id, 'en', 'customertype'),
params: this.params,
headers: headers
})
.then(response => {
this.customerTypeData = response.data.data
for (let index = 0; index < this.customerTypeData.length; index++) {
this.customerTypeData.rating[index] = parseInt(this.customerTypeData.rating[index])
}
this.loading = false
})
}
getCustomerType:函数(存储){
这是真的
让标题={
授权:“承载人”+window.accessToken
}
axios({
方法:“GET”,
url:baseApi(this.selectedStore.url_id'en','customertype'),
params:this.params,
标题:标题
})
。然后(响应=>{
this.customerTypeData=response.data.data
for(让index=0;index
但是parseInt的代码并不能解决这个问题
for (let index = 0; index < this.customerTypeData.length; index++) {
this.customerTypeData.rating[index] = parseInt(this.customerTypeData.rating[index])
}
for(让index=0;index
预期的:
评级(按索引)它通过索引数组从字符串变为数字根据JSON响应,您应该通过以下方式访问评级:
this.customerTypeData[index].rating=parseInt(this.customerTypeData[index].index)
this.customerTypeData.rating[index]应该是this.customerTypeData[index].rating
?你的回应对象暗示了后者。哦,太好了,谢谢@ricardoorellana