如何解析Corona SDK中的JSON数据

时间:2013-06-22 18:07:24

标签: corona

我是corona的新手,我在从corona 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

0 个答案:

没有答案