gpt4 book ai didi

php - iOS JSON 错误 : NSDebugDescription=Garbage at end

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:38:42 25 4
gpt4 key购买 nike

这是一个非常奇怪的错误,当从我的服务器(通过 PHP 生成)获取 JSON 时,我在调用时收到此错误:

json = [NSJSONSerialization JSONObjectWithData:kivaData
options:kNilOptions
error:&jsonError];

JSON 错误:Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn't be completed. (Cocoa error 3840.)"(Garbage at end.) UserInfo=0x178467d00 {NSDebugDescription=Garbage at end.}

我的 (NSData* kivaData) 完美地抓取了所有内容,但它无法解析 JSON。

我已经在 http://jsonlint.com/ 中运行了我的 JSON 代码每次都有效。

这真的很奇怪,因为它可以在我连接到 Wifi 时解析 JSON,但是当我尝试通过蜂窝网络进行解析时,它不会工作。它确实可以在某些人的手机上通过蜂窝网络运行,但每次都是如此。

最佳答案

使用 swift 4,首先使用 print 检查 JSON 数据:

print (String(data:data!, encoding: .utf8)!)

检查空格或不需要的字符,然后删除它们:

var string = String(data: data!, encoding: .utf8)
string = string?.replacingOccurrences(of: "/r/n", with: "")

之后,将字符串赋值给数据变量:

let data1 = string!.data(using: .utf8)

关于php - iOS JSON 错误 : NSDebugDescription=Garbage at end,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25317060/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com