JSON Parse Swift [Google Translate API]

1.2k views Asked by At

I'm developing a Translator App on Menubar for MacBooks.

Problem:

I can't parse JSON results from Google Translate API.

Example JSON result:

{
 "data": {
  "translations": [
   {
    "translatedText": "Hello World"
   }
  ]
 }
}

Please help me!

Edit : Add my codes

http://imgim.com/ekranresmi2015-06-21112615.png

and i use SwiftHTTP for http requests. https://github.com/daltoniam/SwiftHTTP

2

There are 2 answers

0
Halil ONCEN On BEST ANSWER

I solved problem use SwiftyJSON :)

https://github.com/SwiftyJSON/SwiftyJSON

1
Randika Vishman On

I hope according to your given screenshot of your code sample your JSON string is containeed within the str variable. So solution would be something like as follows:

NSString *translatedText = str["data"]["translations"][0]["translatedText"];

I suggest you to read the following given tutorial link.

  1. http://www.raywenderlich.com/82706/working-with-json-in-swift-tutorial