如何使用javascript、jquery和jsonp在android上使用web api

How to use web api on android using javascript, jquery and jsonp?

本文关键字:android api web jsonp javascript 何使用 jquery      更新时间:2023-09-26

im试图在我的android程序中设置一个按钮,当按下该按钮时,它会从web api中获取一些信息,并在屏幕上显示结果。

这是完成所有工作的代码,但我需要把它放在我的android页面上:

<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<script type="text/javascript">
<!--
function get_temp(){
var url = "http://api.wunderground.com/api/00000000003/conditions/q/';
    url+=$('#lat').val()+','+$('#lon').val()+' .json?callback=?';
    $('#log').html($('#log').html()+url);
    $.getJSON(url, function(data) {
        var temp = data['current_observation']['temp_c'];
        $('#out').html($('#shoedata').html()+temp+'<br>');
    });
 }
 //-->
</script>
Latitude <input type="text" name="name" id="lat" />
Longitude <input type="text" name="name" id="lon" />
<input value="Get temperatura" type="button" onclick="get_temp()"/>
<div id='out'>Current temperature: </div>
<div id="log">Log: </div>
</body>
</html>

我该怎么做?在android中编写js代码应该遵循哪些步骤?jquery和jsonp也有什么不同吗?谢谢

嗨,朋友使用下面的链接。

http://developer.android.com/reference/android/webkit/WebView.html

JSON,XML连接到Android的web api?

希望这些能帮助你。