【问题标题】:Apiary io mixing up json from iOSApiary io 混合来自 iOS 的 json
【发布时间】:2014-11-14 02:19:10
【问题描述】:

我正在尝试将一个简单的 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还有重复数据。

【问题讨论】:

    标签: ios json apiblueprint apiary.io apiary


    【解决方案1】:

    尝试将您的请求更改为:

    + Request (application/json)
    
            {"city":"city","state":"Alabama","gender":"Male","street":"101  ","password":"password","graduationYear":"2014","email":"joe@joe.com","school":"Abcott Institute","name":"joe"}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-03
      • 2018-12-19
      • 1970-01-01
      • 2021-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多