• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1592
  • Last Modified:

Retrieve json_encode values in javascript array

I am using following PHP code to store column values and pass to JSON function:

echo json_encode(array($PostedDate.$Places.$Company.$Designation.$ProjectDetails.$DesiredCandidate.$HRName.$HRContact.$Email));

The above thing is returned in a variable called 'data' to JSON function. I want to store the above values in JavsScript array? How to do that?
  • 2
1 Solution
The point of JSON is to have them stored as JS objects.

So if you have in your JavaScript:

var data = {"a":1, "b":2, "c":3};

You can then access it as such:


Let me know if that is fine. If you really want a JS array, you can loop over the array instead of running a json_encode() over it and output it with JS array syntax.
rpkhareAuthor Commented:
Following code calls the code I mentioned in my original post. Please let me know how to modify it?

							$.getJSON("fetchvalues.php?UpdateRecordID=" + $.cookie('UpdateRecordID'),
							// Data retrieved in concatenated form. So we will break it and store values in array.
							var concatenatedvalues = new Array();
							concatenatedValues = data;

Open in new window

rpkhareAuthor Commented:
Ok, I solved this problem. Someone suggested me to use commas instead of period is this code:

echo json_encode(array($PostedDate.$Places.$Company.$Designation.$ProjectDetails.$DesiredCandidate.$HRName.$HRContact.$Email));

Now, from within I can call a column simply like:


Please note that the data is a function used by JSON to retrieve results.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now