How SOAP and REST work with XML/JSON response?

前端 未结 3 1226
被撕碎了的回忆
被撕碎了的回忆 2021-01-30 07:53

This is one very common question asked again and again on stack overflow and I read so many answers about this but I am still bit confused.

I need to call the webservice

3条回答
  •  心在旅途
    2021-01-30 08:21

    Ok, so you have a few different questions here:

    1. REST is a way of accessing the web service. SOAP is an alternative way of accessing the web service. REST uses query string or URL format whereas SOAP uses XML. JSON and XML are two different ways of sending back data. SOAP and XML are usually associated with each other. For mobile apps, REST/JSON is usually the way to go. Easier to implement and maintain, far more telegraphic, etc.

    2. ASIHTTP, as Bill notes, is a wrapper. There are other choices that do similar things depending on what you need. If you are using REST/JSON then NSURLConnection + SBJSON might do the trick, I like it personally.

    3. If your SOAP service has an available WSDL you can use wsdl2objc to automatically build the code for your parsing and fetching. If it is a JSON service or no WSDL is available, I would recommend using SBJSON and simply parsing in the following way:

      for (id jsonElement in repsonse) { self.propertyA = [jsonElement valueForKey:@"keyA"]; self.propertyB = [jsonElement valueForKey:@"keyB"]; }

    Hope that helps!

提交回复
热议问题