4 Replies
      Latest reply: Dec 11, 2016 1:42 PM by eskimo RSS
      essinfo Level 1 Level 1 (0 points)

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

        Could someone pass an example?

         

        Edilson

        • Re: How to send a JSON object to a restfull java server?
          eskimo Apple Staff Apple Staff (7,530 points)

          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"

            • Re: How to send a JSON object to a restfull java server?
              essinfo Level 1 Level 1 (0 points)

              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": "teste", "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")

                  }

                • Re: How to send a JSON object to a restfull java server?
                  essinfo Level 1 Level 1 (0 points)

                  How to code a JSON in swift 3.0

                  
                  
                       func EnviarJSONWebService()
                      {
                          let myData: [String: Any] = ["title": "My First todo", "completed": "teste", "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")
                      }