Apiary io mixing up json from iOS

169 views Asked by At

I am trying to send a simple json object from iOS to apiary server. I printout my json object after creating it and everything looks good. But apiary is showing everything mixed up. If I have only one item, then it looks fine.

Here I create the object and encode it

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)

Next I use AFNetworking to send the data

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)")
    })

Logging the decoded json object I get

{"city":"city","state":"Alabama","gender":"Male","street":"101  ","password":"password","graduationYear":"2014","email":"[email protected]","school":"Abcott Institute","name":"joe"}

Finally, on apiary I get the following enter image description here

The json is all mixed up. I am not sure if AFNetworking is the culprit or of apiary is mixing it up and I shouldn't worry about it because the real server will not have this issue.

Finally, here is how I am setting up apiary enter image description here

Anyone see anything dubious that I am doing? Thank you

Oh, in addition to mixing things up, the json has repeated data.

1

There are 1 answers

0
LilyJ On

Try changing your request to:

+ Request (application/json)

        {"city":"city","state":"Alabama","gender":"Male","street":"101  ","password":"password","graduationYear":"2014","email":"[email protected]","school":"Abcott Institute","name":"joe"}