如何解析JSON在PhoneGap? [英] How to parse JSON in PhoneGap?
问题描述
我使用PhoneGap框架实现了一个移动应用程序。我不知道如何在PhoneGap中解析JSON。
你可以建议我吗?
Phonegap让你使用简单的javascript界面调用gps等设备功能。
要解析JSON对象,两种方法:
清洁示例,
-
首先,包含jquery,将更容易
-
使用id =searchButton (包含id =dataParsed)和包含id =searchBox的文本框
-
包含此代码:
$('#searchButton')。click(function(){
$ .getJSON('http://api.alternativeto.net/software/'+$ '#searchBox')。val()+'/?count = 15',
function(data){
var items = data.Items;
//取消注释行查看json的结构
//console.log(items);
var list = $('#dataParsed');
list.html( );
$ .each(items,function(key,val){
list.append($(document.createElement('p'))。html(val.Name)) ;
});
});
});
json + ajax + jquerymobile :在phonegap维基中阅读:
http://wiki.phonegap.com/w/page/36868306/UI%20Development%20using%20jQueryMobile
祝你好运! :)
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?
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! :)
这篇关于如何解析JSON在PhoneGap?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!