在 iPhone 上调试以不同于模拟器的方式解析 JSON 值
Debugging on iPhone Parses JSON Values Differently vs. Simulator
我遇到一个问题,当我 运行 我的 iPhone 上的应用程序时,我的 table 视图中填充了看起来像中文字符的内容。但是,当我通过模拟器 运行 应用程序时,我得到了预期的(英语)结果。以下是问题的截图。
运行 在模拟器中
运行 在 iPhone
下面是填充对象的代码
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)
}
}
}
当我在其中放置一个断点时,返回的 JSON 值看起来被不同地解析了。
模拟器中应用 运行ning 的输出
应用 运行ning 在 iPhone 上的输出
我认为这可能是本地化设置或 phone 上的某个地方,但不知道如何确定是否是这种情况。我试过从 phone 中删除该应用程序并重新安装,但也无济于事。
我使用的框架是 Facebook SDK、Alamofire 和 Swifty-JSON,以防其中任何一个可能导致这个奇怪的问题。
通常这是 HTTP 请求中的 Accept-Language
header 的问题。设备是否设置为另一种语言?如果是这样,它将默认为该语言。您可以通过使用 NSMutableURLRequest
并将该值更改为 described here.
来手动更改 header 值
您获得了不同的本地化数据版本。在你的例子中——“クイ–ン”是"Queen"的日文Katakana音译。 JSON 解析问题不会将罗马文本转换为日语音译,因此您会得到 JSON 不同的内容。
我遇到一个问题,当我 运行 我的 iPhone 上的应用程序时,我的 table 视图中填充了看起来像中文字符的内容。但是,当我通过模拟器 运行 应用程序时,我得到了预期的(英语)结果。以下是问题的截图。
运行 在模拟器中
运行 在 iPhone
下面是填充对象的代码
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)
}
}
}
当我在其中放置一个断点时,返回的 JSON 值看起来被不同地解析了。
模拟器中应用 运行ning 的输出
应用 运行ning 在 iPhone 上的输出
我认为这可能是本地化设置或 phone 上的某个地方,但不知道如何确定是否是这种情况。我试过从 phone 中删除该应用程序并重新安装,但也无济于事。
我使用的框架是 Facebook SDK、Alamofire 和 Swifty-JSON,以防其中任何一个可能导致这个奇怪的问题。
通常这是 HTTP 请求中的 Accept-Language
header 的问题。设备是否设置为另一种语言?如果是这样,它将默认为该语言。您可以通过使用 NSMutableURLRequest
并将该值更改为 described here.
您获得了不同的本地化数据版本。在你的例子中——“クイ–ン”是"Queen"的日文Katakana音译。 JSON 解析问题不会将罗马文本转换为日语音译,因此您会得到 JSON 不同的内容。