在日冕中明智地显示json数据页面

时间:2013-06-24 16:56:51

标签: corona

我正在从JSON检索数据,但是整个数据都显示在我的页面上, 但我想以页面方式显示它,例如。第一页1到10, 当用户按下按钮时,显示其余记录,我正在工作 在那,但无法解决它,在Corona中有任何Paging的概念, 或者请就此问题提供帮助,谢谢..

这是我的json数据结构:

My code for displaying JSON data:



 local test=json.decode(event.response)
    local datas=test.data
    for name, users in pairs(datas) do
       for names, usernames in pairs(users ) do
          for tag,value in pairs(usernames) do
           cid=value.customerid
           cname=value.customername
           print(cname)
           print(cid)
          end
       end
    end

这是我的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"
    }
   }
  ]
 }
}

2 个答案:

答案 0 :(得分:0)

这里有一个关于如何获取JSON数据的提示我只是在这里得到名字和姓氏我只是复制你的json数据并把它放在文本文件名称数据上

local json = require "json"
local txt
local path = system.pathForFile( "data.txt", system.ResourceDirectory )
data = {}
local file = io.open( path, "r" )
if file then
       -- read all contents of file into a string
       txt = file:read( "*a" )
       io.close( file ) -- close the file after using it
end

local t = json.decode (txt)



for i = 1, table.getn(t["data"]["marks"]), 1 do

print(t["data"]["marks"][i]["Marks"]["first_name"])
print(t["data"]["marks"][i]["Marks"]["last_name"])


end

答案 1 :(得分:0)

上面的示例代码只是将打印件转储到控制台。我假设最后你想在屏幕上显示它。我建议使用widget.newTableView()让系统为你处理滚动。

http://docs.coronalabs.com/api/library/widget/newTableView.html