如何解析JSON在PhoneGap? [英] How to parse JSON in PhoneGap?

查看:117
本文介绍了如何解析JSON在PhoneGap?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用PhoneGap框架实现了一个移动应用程序。我不知道如何在PhoneGap中解析JSON。



你可以建议我吗?

解决方案

Phonegap让你使用简单的javascript界面​​调用gps等设备功能。



要解析JSON对象,两种方法:



清洁示例


  1. 首先,包含jquery,将更容易




  2. 使用id =searchButton (包含id =dataParsed)和包含id =searchBox的文本框


  3. 包含此代码:

      $('#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,

  1. first, include jquery, will be more easy

  2. make a button with id = "searchButton", a div with id="dataParsed" and a textbox with id="searchBox"

  3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆