我正在尝试将一个简单的 json 对象从 iOS 发送到养蜂场服务器。我在创建它后打印出我的 json 对象,一切看起来都很好。但是养蜂场把一切都搞混了。如果我只有一个项目,那么它看起来不错。
在这里我创建对象并对其进行编码
let jsonDict = ["name":student.name,
"email":student.email,
"password":student.password,
"gender":student.gender,
"graduationYear":student.graduationYear,
"school":student.school,
"street":student.address.address,
"city":student.address.city,
"state":student.address.state
]
var error: NSError?
let jsonData = NSJSONSerialization.dataWithJSONObject(jsonDict, options: NSJSONWritingOptions(0), error: &error)
let s = NSString(data: jsonData!, encoding: NSUTF8StringEncoding)
println(s)
接下来我使用 AFNetworking 发送数据
let manager = AFHTTPRequestOperationManager(baseURL: NSURL(string: "\(server)"))
manager.POST("students", parameters: nil,
constructingBodyWithBlock: { (data: AFMultipartFormData!) in
data.appendPartWithFormData(jsonData!, name: "json")
data.appendPartWithFileData(imageData, name: "image", fileName: "image.jpg", mimeType: "image/jpeg")
},
success: { operation, response in
println("[success] operation: \(operation), response: \(response)")
},
failure: { operation, error in
println("[fail] operation: \(operation), error: \(error)")
})
记录我得到的解码的 json 对象
{"city":"city","state":"Alabama","gender":"Male","street":"101 ","password":"password","graduationYear":"2014","email":"joe@joe.com","school":"Abcott Institute","name":"joe"}
最后,在养蜂场我得到以下信息
json都混在一起了。我不确定 AFNetworking 是罪魁祸首还是 apiary 混合了它,我不应该担心它,因为真正的服务器不会有这个问题。
最后,这是我设置养蜂场的方式
有人看到我在做什么可疑的事情吗?谢谢
哦,除了混淆之外,json还有重复的数据。