SimpleJSON add new element to the end of the Array

Hi,

Im using SimpleJSON from here: http://wiki.unity3d.com/index.php/SimpleJSON

At the examples section, it is shown that I can add a new element to the end of the Array as following:

N["data"]["sampleArray"][-1] = "Test";         // this will add another string to the end of the array
N["data"]["sampleArray"][-1]["name"] = "FooBar"; // this will add another object to the end of the array which contains a string named "name"

However, I get error at the editor such as:

The best overloaded method match for `string.this[int]' has some invalid arguments

Argument `#1' cannot convert `string' expression to type `int'

Am I doing something wrong here?

Alright, it was my mistake,I had to intantiate the variable with SimpleJSON.JSONNode N = ""; then it does not give any error…

@orkungo Thanks for posting this! I myself tried to use " N[“data”] = “FooBar”; in my code, and I get no compiler errors, but I can’t save anything to the json with that line (reading works just fine). What did you end up doing?