I'm just starting to learn this JSON-stuff, but I cant get it to work.
I am using the JSON class from here:
http://www.json.org/json.asI have a php-script that collects some info on a given month of the year, stores that as a multidimensional array, then converts that array to a JSON object using the built in php function json_encode. (info here:
http://usphp.com/manual/en/function.json-decode.php)
Then I echo that string. This seems to work. If I just look at the echoed output in a browser it reads:
-----------
{"day1":{"weekday_number":
"1","name_
abbr":"Mon
","name_fu
ll":"Monda
y"},"total
_days":"30
","day2":{
"name_abbr
":"Tue","n
ame_full":
"Tuesday",
"weekday_n
umber":2},
"day3":{"n
ame_abbr":
"Wed","nam
e_full":"W
ednesday",
"weekday_n
umber":3},
"day4":{"n
ame_abbr":
"Thu","nam
e_full":"T
hursday","
weekday_nu
mber":4},"
day5":{"na
me_abbr":"
Fri","name
_full":"Fr
iday","wee
kday_numbe
r":5},"day
6":{"name_
abbr":"Sat
","name_fu
ll":"Satur
day","week
day_number
":6},"day7
":{"name_a
bbr":"Sun"
,"name_ful
l":"Sunday
","weekday
_number":0
},"day8":{
"name_abbr
":"Mon","n
ame_full":
"Monday","
weekday_nu
mber":1},"
day9":{"na
me_abbr":"
Tue","name
_full":"Tu
esday","we
ekday_numb
er":2},"da
y10":{"nam
e_abbr":"W
ed","name_
full":"Wed
nesday","w
eekday_num
ber":3},"d
ay11":{"na
me_abbr":"
Thu","name
_full":"Th
ursday","w
eekday_num
ber":4},"d
ay12":{"na
me_abbr":"
Fri","name
_full":"Fr
iday","wee
kday_numbe
r":5},"day
13":{"name
_abbr":"Sa
t","name_f
ull":"Satu
rday","wee
kday_numbe
r":6},"day
14":{"name
_abbr":"Su
n","name_f
ull":"Sund
ay","weekd
ay_number"
:0},"day15
":{"name_a
bbr":"Mon"
,"name_ful
l":"Monday
","weekday
_number":1
},"day16":
{"name_abb
r":"Tue","
name_full"
:"Tuesday"
,"weekday_
number":2}
,"day17":{
"name_abbr
":"Wed","n
ame_full":
"Wednesday
","weekday
_number":3
},"day18":
{"name_abb
r":"Thu","
name_full"
:"Thursday
","weekday
_number":4
},"day19":
{"name_abb
r":"Fri","
name_full"
:"Friday",
"weekday_n
umber":5},
"day20":{"
name_abbr"
:"Sat","na
me_full":"
Saturday",
"weekday_n
umber":6},
"day21":{"
name_abbr"
:"Sun","na
me_full":"
Sunday","w
eekday_num
ber":0},"d
ay22":{"na
me_abbr":"
Mon","name
_full":"Mo
nday","wee
kday_numbe
r":1},"day
23":{"name
_abbr":"Tu
e","name_f
ull":"Tues
day","week
day_number
":2},"day2
4":{"name_
abbr":"Wed
","name_fu
ll":"Wedne
sday","wee
kday_numbe
r":3},"day
25":{"name
_abbr":"Th
u","name_f
ull":"Thur
sday","wee
kday_numbe
r":4},"day
26":{"name
_abbr":"Fr
i","name_f
ull":"Frid
ay","weekd
ay_number"
:5},"day27
":{"name_a
bbr":"Sat"
,"name_ful
l":"Saturd
ay","weekd
ay_number"
:6},"day28
":{"name_a
bbr":"Sun"
,"name_ful
l":"Sunday
","weekday
_number":0
},"day29":
{"name_abb
r":"Mon","
name_full"
:"Monday",
"weekday_n
umber":1},
"day30":{"
name_abbr"
:"Tue","na
me_full":"
Tuesday","
weekday_nu
mber":2}}
-----------
It seems to be formatted okay.
This string is what I want to load into flash, and then convert it to a multidimensional array again in flash.
So I have this code in actionscript (see attached)
I do load the string, I know that much, because trace(jsonString) outputs a string.
However, all the quotes are escaped with backslashes. So the trace óf the loaded string looks like this:
-----------
{"{\"day1\":{\"weekday_num
ber\":\"1\
",\"name_a
bbr\":\"Mo
n\",\"name
_full\":\"
Monday\"},
\"total_da
ys\":\"30\
",\"day2\"
:{\"name_a
bbr\":\"Tu
e\",\"name
_full\":\"
Tuesday\",
\"weekday_
number\":2
},\"day3\"
:{\"name_a
bbr\":\"We
d\",\"name
_full\":\"
Wednesday\
",\"weekda
y_number\"
:3 ........ etc etc
---------
So my questions:
- why are the quotes escaped with backslashes? Does this matter when I try to convert the string to an object? Why is this happening?
- I want to make this string into an array in flash... how do I do it? and how do I access the items in the array once it has been converted to an array?
Start Free Trial