| Author |
How to Parse JASON response
|
Shweta Machhe
Greenhorn
Joined: Nov 22, 2011
Posts: 8
|
|
Hi ,
I want to translate my english string to french. so i am using https://www.googleapis.com/language/translate/ API.
It works as follows
https://www.googleapis.com/language/translate/v2?key=YOUR KEY&q=TEXT TO TRANSLATE&source=SOURCE LANGUAGE CODE&target=TARGET LANGUAGE CODE
it returns me a JASON object.
{
"data": {
"translations": [
{
"translatedText": "bonjour"
}
]
}
}
How should i parse it, to access translated sting in my java code?
|
 |
Tim Moores
Rancher
Joined: Sep 21, 2011
Posts: 2407
|
posted

0
|
|
On json.org you'll find numerous Java libraries for handling JSON data.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56162
|
|
|
JSON, not JASON,
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Pranav Raulkar
Ranch Hand
Joined: Apr 20, 2011
Posts: 73
|
|
Hi Shweta,
To parse JSON in Java you'll need to import json-lib-2.2.2-jdk15.jar into your project.
Once you have done that all you need to do is
where s is the string representing the returned JSON string.
This will give you an Object. Convert it into JSONArray
and get the element you need, for instance
Hope this helps.
|
 |
Ivan Krizsan
Bartender
Joined: Oct 04, 2006
Posts: 2193
|
|
Hi!
An alternative may be Jackson, a JSON parser which performs well and is easy to work with: http://jackson.codehaus.org/
Best wishes!
|
My free books and tutorials: http://www.slideshare.net/krizsan
|
 |
 |
|
|
subject: How to Parse JASON response
|
|
|