2013-06-24 35 views
0

我從JSON檢索數據,但整個數據顯示在我的頁面上, 但我想明智地顯示它,例如。第一頁1到10, 和當用戶按下按鈕,其餘的記錄顯示,我工作 那,但不能解決它,是否有任何概念的電暈, 或請提供對於這個問題,感謝幫助..在日冕顯示JSON數據頁明智

這裏是我的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" 
    } 
    } 
    ] 
} 
} 
+0

你爲什麼不只是循環它由10而不是環路,所有 – DevfaR

+0

能否請您給我一些暗示我怎麼可以在這裏使用循環。 – dk3611

+0

你能提供你的json數據的鏈接 – DevfaR

回答

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