Reputation: 1073
I am implementing a mobile application using PhoneGap framework. I don't know how to parse JSON in PhoneGap.
Can you advise me for that?
Upvotes: 2
Views: 20030
Reputation: 13
You can use 2 methods for parsing JSON Data
Upvotes: 0
Reputation: 1156
Phonegap let´s you call to device functions like gps with a simple javascript interface.
To parse a JSON object you can try this two ways:
Clean example,
first, include jquery, will be more easy
make a button with id = "searchButton", a div with id="dataParsed" and a textbox with id="searchBox"
include this code:
$('#searchButton').click(function() {
$.getJSON('http://api.alternativeto.net/software/'+$('#searchBox').val()+'/?count=15',
function(data) {
var items=data.Items;
// uncomment the line to see the structure of the json
//console.log(items);
var list = $('#dataParsed');
list.html("");
$.each(items, function(key, val) {
list.append($(document.createElement('p')).html(val.Name));
});
});
});
Example of json+ajax+ jquerymobile: Read this in the phonegap wiki:
http://wiki.phonegap.com/w/page/36868306/UI%20Development%20using%20jQueryMobile
Good Luck! :)
Upvotes: 6
Reputation: 141
This is more a JavaScript than a PhoneGap question.
It should be safe to use JSON.parse(myJsonString)
since no old browsers are going to be used with PhoneGap.
Upvotes: 7
Reputation: 12068
actually I think you are little confused, phonegap doesn't let you parse json, you parse json with javascript (like crokford json parser library or jquery json parsing methods) the only thing phonegap does is expose the native api of various mobile operation systems to a common javascript interface.
Upvotes: 2