0

I'm having an issue where my table view is getting populated with what looks to be chinese characters when I run the app on my iPhone. However, when I run the app through simulator, I get the expected (English) result. Below are screenshots of the issue.

Running in Simulator Running in Simulator

Running on iPhone Running on iPhone

Below is the code that populates the objects

private func populateArtists(_ maxRecordsToPopulate: Int, json: JSON) {

    let artists = json["artists"]["items"]

    for i in 0 ..< artists.count {

        if i < maxRecordsToPopulate {

            let artist = Artist()

            print(artists[i]["name"].string!)

            artist.name = artists[i]["name"].string!
            artist.detailUrl = artists[i]["href"].string!
            artist.id = artists[i]["id"].string!

            self.searchResults.artists.append(artist)

        }

    }

}

When I place a breakpoint inside, it looks like the JSON values being returned are being parsed differently.

Output from app running in Simulator Output from app running in Simulator

Output from app running on iPhone Output from app running on iPhone

I thought this might be a localization setting or something somewhere on the phone, but have no clue how to find out if that's the case. I've tried deleting the app from the phone and reinstalling and that didn't help either.

Frameworks I'm using are Facebook SDK, Alamofire, and Swifty-JSON, in case any of those could be causing this weird issue.

dst3p
  • 1,008
  • 11
  • 25

2 Answers2

2

Usually this is an issue with the Accept-Language header in the HTTP request. Is the device set to another language? If so, it will default to that language. You can manually change the header value by using an NSMutableURLRequest and changing that value as described here.

Community
  • 1
  • 1
EricS
  • 9,650
  • 2
  • 38
  • 34
  • 1
    The device wasn't set to another language, but for whatever reason it added the Japanese language under Settings > General > Language & Region. My guess is one of my kids got ahold of my phone and added that accidentally. Thanks for pointing me in the right direction. – dst3p Oct 12 '16 at 03:05
1

You're getting a different localized version of the data. In your example-- "クイ–ン" is the Japanese Katakana transliteration of "Queen". JSON parsing issues aren't going to convert Roman text into Japanese transliterations, so you're getting JSON with different contents.

Tom Harrington
  • 69,312
  • 10
  • 146
  • 170