0

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

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

2 回答 2

0

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

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

于 2013-07-01T00:49:31.307 回答
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
于 2013-06-28T08:38:33.017 回答