I am doing accepted answer here but it doesn't work for me. I get NULL
.
I produce JSON from an array with:
NSError* error;
NSData *result =[NSJSONSerialization dataWithJSONObject:self.fileNamesListForUpload options:0 error:&error];
NSString *displayJson = [[NSString alloc] initWithData:result
encoding:NSUTF8StringEncoding];
NSLog(@"json result %@",displayJson);
this prints ["sample.pdf","sample-1.pdf"]
then I use following command to post the string
curl -F "nameList=["sample.pdf","sample-1.pdf"]" url
In my php code;
//get json string
$jsonString = $_POST["nameList"];
var_dump($_POST["nameList"]);
$arrayOfNames=json_decode($jsonString,true);
var_dump($arrayOfNames);
echo "ArrayOfNames: ",$arrayOfNames,"\n";
Result is;
string(25) "[sample.pdf,sample-1.pdf]"
NULL
ArrayOfNames:
or if I add quotes '' I get;
string(27) "'[sample.pdf,sample-1.pdf]'"
NULL
Why "" are dismissed when I use _POST? [sample.pdf,sample-1.pdf]
I am posting ["sample.pdf","sample-1.pdf"]
?
How can I parse json string and put it into an array?