Getting a specific key value using Corona SDK

0 votes
Can you provide example code that demonstrates how to iterate through values stored in a JSON database collection document and then, more importantly, retrieve a specific key value from that document? Thanks! Brian
asked Jun 8, 2016 in Corona by brian (15 points)

1 Answer

0 votes
 
Best answer

Hi Brian,

 

You can find code snippet from here to get the document from the collection. However for retrieving a specific value from JSON object (JSON document) you can simply use below code snippet and let me know if it helps :

 

for i=1,table.getn(object:getJsonDocList()) do
print("DocId is "..object:getJsonDocList()[i]:getDocId())
local jsonDocument = object:getJsonDocList()[i]:getJsonDoc();
 
print("JSON Document is "..jsonDocument["Key name which you value you want to iterate"])
 
end
 
Regards,
Himanshu Sharma

print("CreatedAt is "..object:getJsonDocList()[i]:getCreatedAt())

answered Jun 9, 2016 by hs00105 (2,005 points)
selected Jun 12, 2016 by brian
Worked like a charm... thank you!
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...