How to send a JSON object to a restfull java server?

Please, how to send a JSON object to a restfull java server?

Could someone pass an example?


Edilson

Replies

Typically you do this using NSURLSession for the HTTP-level networking and NSJSONSerialization for converting Foundation (or Swift) objects to JSON and back. It’s hard to offer more specific advice without knowing more about your constraints (for example, what platform are you developing for? and what language are you planning to use?) but if you search be able to search the ’net for those terms and find a bunch of resources, both Apple and non-Apple.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Please,

How to code a JSON in swift 3.0, segue my basic example follow?


func EnviarJSONWebService()

{

let myData: [String: Any] = ["title": "My First todo", "completed": "*****", "userId": "1"]

print(myData)

let myJSON: Data

do {

myJSON = try JSONSerialization.data(withJSONObject: myData, options: [])

print("GEREI O JSON")

let valid = JSONSerialization.isValidJSONObject(myJSON) /

print("Resultado : \(valid)")

} catch {

print("Error: cannot create JSON from todo")

}

print("cheguei no fim")

}

How to code a JSON in swift 3.0

     func EnviarJSONWebService()
    {
        let myData: [String: Any] = ["title": "My First todo", "completed": "*****", "userId": "1"]
      
        print(myData)
      
        let myJSON: Data
        do {
            myJSON = try JSONSerialization.data(withJSONObject: myData, options: [])
            print("GEREI O JSON")
          
            let valid = JSONSerialization.isValidJSONObject(myJSON) /
            print("Resultado : \(valid)")
          
        } catch {
            print("Error: cannot create JSON from todo")
            return
        }
        print("cheguei no fim")
    }

How to code a JSON in swift 3.0

The code you posted is valid Swift 3. What’s your actual question?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"