Return response as array instead of as an object in Contentful - response

I need to receive an array of objects as response from Contentful API. I tried to use "?select=fields" but that again returns an object with property items which is an array. I want to get the items array directly as a response is there a way to do this?

I don't think that's possible with the Contentful API. To my knowledge, it always returns items.

Related

Different response on Console and infoView in ObjectiveC

I have to show the response with same order as I have received from my backend team.
But the response sequence is getting changed on extracting the values from Dictionary and array.
Please check the attached screenshot and suggest .
On extracting , I am getting 7703 but I need 5599 for showing the same position as in my website and in my application
Dictionary is not an ordered collection. You should create custom model class and use array of models.
You can use famous third party https://github.com/jsonmodel/jsonmodel
for mapping json to array of models.
Or you can sort dictionary keys (dict.allKeys) or values (dict.allValues)

Swift 2.0: How to implement tableview controller with JSON API

I think this is a probably repeat question.
I am new to ios and and I am trying to learn so I don't expect response in actual codes. I still want to write them myself.
Here's what I have done so far:
I wrote codes to make web api calls, authenticate and pull json data.
I've figured out how to parse json data that I pulled from web.
I have made tableview controller.
Challenge: How do I get the parsed Json data to tableview controller?
Do I:
- save it locally into like NSUSERDefaults variable?
- save it to a global variable shared by controller and my model?
- at the end of the parsing json data do a return so that it will be saved into viewController?
- or none of the above and do ______________ (insert your answer)
What's the cleanest way to do this? The table will initially have like 20 rows but as you pull down you will get more rows.
Best way to save data on model class while parsing and store this class objects in an array and in cellforrowatindexpath get objects of model class from array and show data using these objects.

Cloud Code Parameters and Results

I'm making an iOS app using swift and am using a cloud backend for the first time, namely Parse.com. I am curious what I can pass as parameters to cloud code functions and then receive as a return value. I want to send an array of PFObjects and also return an array of them, but I get the error Caught "NSInternalInconsistencyException" with reason "PFObjects are not allowed here." I am thinking of instead sending an array of dictionaries of the values I need to send and then return the same way. Can I do it this way, or is there another, better way to do this?

How to retain order of JSON data retrieved with AFNetworking?

I am using AFNetworking to retrieve JSON data from a web service. Part of the response string I get is:
{"DATA":{"LEASE TYPE":"3 Yrs + 0 renew of 0 Yrs","LANDLORD":"","TENANT":"test comp"...
and so on. The order of the key values in the "DATA" dictionary ("LEASE TYPE","LANDLORD","TENANT"...) is important for presentation purposes. However, when AFNetworking calls NSJSONSerialization's:
+ (id)JSONObjectWithData:(NSData *)data options:(NSJSONReadingOptions)opt error:(NSError **)error;
method, the returned dictionary has the keys in a different order.
I notice that the AFJSONRequestOperation object has the server's response stored as an NSString, with everything in the correct order. However I'm not keen on parsing the JSON by hand if I can avoid it.
Can anyone suggest a way that will let me get at / keep the keys in their original order?
Thanks.
If the order is important use an array not a dictionary, dictionaries are be by their nature unordered. Or add an array of dictionary keys in the order desired.
If you have no control over the response that is sent you will have to parse the JSON yourself at least for the ordering.
When you'r creating an NSDictionary, the order will not be the same. I often recognized that dictionaries get ordered by key-name alphabetically.
But when using dictionaries the order doesn't really matter. And they shouldn't!
As the previous answers mentions dictionaries are by nature without order, but you can find here a nice class of OrderedDictionary:
http://www.cocoawithlove.com/2008/12/ordereddictionary-subclassing-cocoa.html
http://projectswithlove.com/projects/OrderedDictionary.zip

In AFNetworking's JSONRequestOperationWithRequest:success:failure: method, what type of object is the JSON response?

It gives you a variable called JSON of type id, but how do I manipulate this? Is it a string? Do I have to serialize it first? How exactly do I interact with it?
It is returned in the form of dictionary, you just need to extract the value based on the key. Example :
[JSON valueForKey:#"key"];
You can get more than the basics
here
Fantastic course, there's very good code about json handling in the photo mania app.

Resources