Advertisement

07.21.2008 at 12:59PM PDT, ID: 23583206
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.6

How convert JSON string to multidimensional array?

Asked by NiklasMoller in ActionScript, JavaScript, Asynchronous Javascript and XML (AJAX)

Tags: , ,

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.as

I 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_full":"Monday"},"total_days":"30","day2":{"name_abbr":"Tue","name_full":"Tuesday","weekday_number":2},"day3":{"name_abbr":"Wed","name_full":"Wednesday","weekday_number":3},"day4":{"name_abbr":"Thu","name_full":"Thursday","weekday_number":4},"day5":{"name_abbr":"Fri","name_full":"Friday","weekday_number":5},"day6":{"name_abbr":"Sat","name_full":"Saturday","weekday_number":6},"day7":{"name_abbr":"Sun","name_full":"Sunday","weekday_number":0},"day8":{"name_abbr":"Mon","name_full":"Monday","weekday_number":1},"day9":{"name_abbr":"Tue","name_full":"Tuesday","weekday_number":2},"day10":{"name_abbr":"Wed","name_full":"Wednesday","weekday_number":3},"day11":{"name_abbr":"Thu","name_full":"Thursday","weekday_number":4},"day12":{"name_abbr":"Fri","name_full":"Friday","weekday_number":5},"day13":{"name_abbr":"Sat","name_full":"Saturday","weekday_number":6},"day14":{"name_abbr":"Sun","name_full":"Sunday","weekday_number":0},"day15":{"name_abbr":"Mon","name_full":"Monday","weekday_number":1},"day16":{"name_abbr":"Tue","name_full":"Tuesday","weekday_number":2},"day17":{"name_abbr":"Wed","name_full":"Wednesday","weekday_number":3},"day18":{"name_abbr":"Thu","name_full":"Thursday","weekday_number":4},"day19":{"name_abbr":"Fri","name_full":"Friday","weekday_number":5},"day20":{"name_abbr":"Sat","name_full":"Saturday","weekday_number":6},"day21":{"name_abbr":"Sun","name_full":"Sunday","weekday_number":0},"day22":{"name_abbr":"Mon","name_full":"Monday","weekday_number":1},"day23":{"name_abbr":"Tue","name_full":"Tuesday","weekday_number":2},"day24":{"name_abbr":"Wed","name_full":"Wednesday","weekday_number":3},"day25":{"name_abbr":"Thu","name_full":"Thursday","weekday_number":4},"day26":{"name_abbr":"Fri","name_full":"Friday","weekday_number":5},"day27":{"name_abbr":"Sat","name_full":"Saturday","weekday_number":6},"day28":{"name_abbr":"Sun","name_full":"Sunday","weekday_number":0},"day29":{"name_abbr":"Mon","name_full":"Monday","weekday_number":1},"day30":{"name_abbr":"Tue","name_full":"Tuesday","weekday_number":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_number\":\"1\",\"name_abbr\":\"Mon\",\"name_full\":\"Monday\"},\"total_days\":\"30\",\"day2\":{\"name_abbr\":\"Tue\",\"name_full\":\"Tuesday\",\"weekday_number\":2},\"day3\":{\"name_abbr\":\"Wed\",\"name_full\":\"Wednesday\",\"weekday_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
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
var jsondata:LoadVars = new LoadVars();
var JSON:JSON = new JSON();
 
jsondata.onLoad = function() {
	var jsonString:String = JSON.stringify(this);
	trace(jsonString); //this works, but the output shows a string where every " has been escaped like so: \"
	var jsonObject:Object = JSON.parse(jsonString);
	trace (jsonObject);//this outputs [object Object], so it seems some kind of object has been created, but how do I know, and how do I access the items?
};
 
jsondata.load($php_filepath);
[+][-]07.22.2008 at 06:47AM PDT, ID: 22059278

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 14-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 07:05AM PDT, ID: 22059456

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 07:06AM PDT, ID: 22059473

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 07:19AM PDT, ID: 22059640

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 07:51AM PDT, ID: 22060034

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 08:02AM PDT, ID: 22060157

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 08:07AM PDT, ID: 22060226

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 14-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.22.2008 at 08:16AM PDT, ID: 22060327

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 14-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.22.2008 at 08:42AM PDT, ID: 22060602

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 01:22PM PDT, ID: 22063248

View this solution now by starting your 14-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: ActionScript, JavaScript, Asynchronous Javascript and XML (AJAX)
Tags: Macromedia, Flash, 8
Sign Up Now!
Solution Provided By: NiklasMoller
Participating Experts: 1
Solution Grade: A
 
 
[+][-]07.23.2008 at 12:25AM PDT, ID: 22066741

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-43 / EE_QW_2_20070628