I have a JSON array:
{"a":"apple,"b":"banana","c":"carrot"}
I want to split each part of the array into separate variables, i.e.
a = "apple",
b = "banana";
c = "carrot";
My glasses are disabled, but I canβt find the right way to do this. I am new to JSON and read fairly fairly, but what I need seems not to be mentioned in my hands.
EDIT: There seems to be confusion as to whether my array is stringor object. I get a response from PHP as follows:
$json = array(
'a' => $a,
'b' => $b,
'c' => $c,
);
echo json_encode($json);
My JS code is as follows:
var data = ajax.responseText;
data = JSON.parse(data);
I get {"a":"apple,"b":"banana","c":"carrot"}as a result
json.stringify(data);
source
share