json parsing from an url in phonegap app for an android mobiles
Hi friends so far i have been worked only in android native app. First time i am trying to create an app in Phone gap for android devices.
I want to hit an url
and there i get a return data in json
format. I dont know to write a code in javascript
to hit an URL and get back a return data. Please help me by giving a piece of code or any tutorial to hit an url and get the return data. From that returned data i need to do json parsing, pls guide me in json parsing in javascri开发者_JAVA技巧pt
too.
Please help me friends......
It depends if you are trying to do a request using GET or POST. You just need to use JSONRequest
If you are trying to just use a simple GET request then your syntax would look something like this:
requestNumber = JSONRequest.get(
"http://yourdomainname.com/request",
function (requestNumber, value, exception) {
if (value) {
processResponse(value);
} else {
processError(exception);
}
}
);
If you are wanting to use POST and you need to send some information here is an example for that:
requestNumber = JSONRequest.post(
"http://yourdomainname.com/request",
{
username: "user",
action: "actionname"
},
function (requestNumber, value, exception) {
if (value) {
processResponse(value);
} else {
processError(exception);
}
}
);
There is a tutorial of this on the phonegap wiki:
http://wiki.phonegap.com/w/page/36868306/UI%20Development%20using%20jQueryMobile
It just what you are looking for :)
Good Luck!
精彩评论