我是电晕的新手,我在解析来自电晕 sdk 中服务器的 JSON 数据时遇到问题。数据在响应中正确来自服务器并正在打印。解析时,我的变量中没有数据。它要么不显示任何数据,要么显示零值。
这是我的json数据结构:
{
"status":"success",
"data":{
"marks":[
{
"Marks":{
"first_name":"Amit",
"last_name":"Sharma",
"country_id":"20",
"Physics":"50",
"Chemistry":"35",
"Mathematics":"40"
}
},
{
"Marks":{
"first_name":"Amit",
"last_name":"Yadav",
"country_id":"21",
"Physics":"50",
"Chemistry":"35",
"Mathematics":"40"
}
},
{
"Marks":{
"first_name":"Pankaj",
"last_name":"Shukla",
"country_id":"22",
"Physics":"50",
"Chemistry":"35",
"Mathematics":"40"
}
},
{
"Marks":{
"first_name":"Abhishek",
"last_name":"Tiwari",
"country_id":"25",
"Physics":"50",
"Chemistry":"35",
"Mathematics":"40"
}
},
{
"Marks":{
"first_name":"Kashif",
"last_name":"Khan",
"country_id":"20",
"Physics":"50",
"Chemistry":"35",
"Mathematics":"40"
}
},
{
"Marks":{
"first_name":"Ankit",
"last_name":"Sharma",
"country_id":"19",
"Physics":"50",
"Chemistry":"35",
"Mathematics":"40"
}
},
{
"Marks":{
"first_name":"Rahul",
"last_name":"Vishwakarma",
"country_id":"27",
"Physics":"50",
"Chemistry":"35",
"Mathematics":"40"
}
},
{
"Marks":{
"first_name":"Amit",
"last_name":"Tiwari",
"country_id":"30",
"Physics":"50",
"Chemistry":"35",
"Mathematics":"40"
}
},
{
"Marks":{
"first_name":"Amit",
"last_name":"Sharma",
"country_id":"78",
"Physics":"50",
"Chemistry":"35",
"Mathematics":"40"
}
},
{
"Marks":{
"first_name":"Amit",
"last_name":"Sharma",
"country_id":"23",
"Physics":"50",
"Chemistry":"35",
"Mathematics":"40"
}
}
]
}
}
如何复制变量中的 json 数据并将其显示在电晕中,这是我的 json 数据代码
function networkListener(event)
if(event.isError) then
native.setActivityIndicator(false)
print("Network Error")
local ErrText=display.newText(....)
else
native.setActivityIndicator(false)
print("Response".. event.response)
data=json.decode(event.response)
for i=1,#data do
local fname=data.score[i].scores.first_name
print(fname)
end
end
end