How to remove an item from JSON array in Swift (using SwiftyJSON) - ios

Pretty simple and straightforward question.
I have a jsonArray, and i want to delete an item by index. How do I do that?
I tried using the solution from here:
https://github.com/SwiftyJSON/SwiftyJSON/issues/439
Like this:
jsonArray[row]["Likers"].array!.dictionaryObject?.removeValueForKey(index)
But I got this error:
value of type json has no member dictionaryObject

Finally I found the answer to remove an element in JSON (array type) created by SwiftyJSON:
dataObj.arrayObject?.removeAtIndex(m)
By the way, to remove an element when JSON returned by SwiftyJSON in a dictionary type:
jsonObj.dictionaryObject?.removeValueForKey(keyValue)
I'm getting this answer form THIS

you just use
yourJsonArry.removeAtIndex(2)
Hear you just pass the index that you want to remove items

Related

How to get Nested Dictionary Item in Umbraco?

I using Umbraco 7.4.3.
I created few dictionary items (rot item with few children items), like below:
HomePage
Intro
Body
When I try to get dictionary value for sub-item I getting empty string, however for root item I get correct result.
For example,
this call works - returns value according to current language:
#Umbraco.GetDictionaryValue("HomePage")
but this call doesn't work - returns empty string:
#Umbraco.GetDictionaryValue("HomePage.Intro")
Please help!
Make sure the child dictionary item has the full key specified: "HomePage.Intro"
Your tree should look like this:
HomePage
- HomePage.Intro
An example of the dictionary tree I'm currently using:

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.

Traverse through JSon data in dart?

After trying a lot sorry for asking such a trivial question.
Given below screenshot consist of a data that I have successfully received from the server.
I would like to know how to traverse through the data since whenever I try to cast it to something and try a foreach it gives an error.
The actual data sent from the server is a List() type.
I want to know how to cast it to same type and use it here.
I tried casting but it says unexpected token here.
Any help is appreciated.
JSON.parse return type depends on the String you try to parse. See the doc :
Parses json and build the corresponding parsed JSON value.
Parsed JSON values are of the types num, String, bool, Null, Lists of parsed JSON values or Maps from String to parsed JSON values.
From your screenshot, it seems that the return value is a List. You can do something like the following to use it (did you notice the typo in your commented code - .fore) :
final parsedList = JSON.parse(e.data)/*.fore*/;
parsedList.forEach((x){
query('#idData').appendText(x[0]);
query('#idData').appendText(x[1]);
query('#idData').appendText(x[2]);
query('#idData').appendText(x[3]);
});

How to access the array that is value of a QVariantMap?

I have a QVariantMap whose key is a string and value is an array(of ints or strings)
How do I get the individual elements of the array?
map["key"] has a method toList(). Can I apply that to arrays?
Yes,
QString first_string_of_key = QVariantMap["key"].toList()[0];
but this is only for reading. Any attempt to write will not work because QVariant will return a copy of the list. Read this post: Assigning to nested QVariantMap
Maybe you can try this if we say that we have an iterator it moving around the keys:
we could say
if(it.value("key").type()==QMetaType::ByteArray)
std::vector<std::string> vs_array_valus(QVariantMap["key"].value().toArray());
Or direct use as below:
if(QVariantMap["key"].value().type()==QMetaType::ByteArray)
std::vector<std::string> vs_array_valus(QVariantMap["key"].value().toArray());
Hope this Will help.

How to convert JS array to JSON, before passing that to controller (using AJAX - POST call)

I ve a JS array, comprising multiple JS objects.
I want to convert JS array to JSON type, & pass that to controller (using AJAX - POST call).
So that I can retrieve the values from the Array of Objects, in my controller & save them in DB.
NB: I ve tried using $.stringify(myArry), but its not able to send data to controller in JSON format. Also I cant use $.toJSON(myArray), as I m not allowed to include a new plugin in our solution. :(
Plz suggest me any other idea.
Else if anyone can let me know how to deserelize the array in cotroller, that I ve sent by using $.stringify(myArry), that would also great.
Something like
var result = JavaScriptConvert.DeserializeObject(inputContent, JsonDataType);
Per this post, it looks like you'll have to add another plug-in:
JSON stringify missing from jQuery 1.4.1?
The Google solution looks good: http://code.google.com/p/jquery-json/
Or just use the JSON object from Crockford: https://github.com/douglascrockford/JSON-js

Resources