Halil ONCEN
Halil ONCEN

Reputation: 83

JSON Parse Swift [Google Translate API]

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

Upvotes: 1

Views: 1277

Answers (2)

Halil ONCEN
Halil ONCEN

Reputation: 83

I solved problem use SwiftyJSON :)

https://github.com/SwiftyJSON/SwiftyJSON

Upvotes: 1

Randika Vishman
Randika Vishman

Reputation: 8124

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

Upvotes: 1

Related Questions