JSON Basics: What You Need to Know

  You are currently not logged in. You can view the forums, but cannot post messages. Log In | Register

24-Mar-11 00:00
This is a forum topic for discussing the article "JSON Basics: What You Need to Know":


What is JSON, and what can it do? In this tutorial you learn how to use JSON to easily move data around the web. You also look at how to work with JSON using both JavaScript and PHP.
01-Apr-11 17:53
I have been reading ans studying your article on Json and it is really good but I can't seem to parse and display the individual elements of the following. I am pasting the json and the code I'm trying to use. I modified it from your example but of course I'm doing something wrong.

I would rather not use the 'true' to create the array but would like to know how to parse this json both ways.

Thank You for your help,


$jsonString = '
"textbox1":"Car dealership",
"textbox15":"R&R Data: 3\/31\/2011 8:17:42 AM"
"textbox17":"TOTAL for Acct 205 => 10 Days",
"Description":"Contracts In Transit",
"BankNameOrCarLine":"Auto Finance"
"Description":"Contracts In Transit",
"BankNameOrCarLine":"C A C"

$cart = json_decode( $jsonString,true );
04-Apr-11 02:38
@kvandiver: This tool is very useful


As you can see, the problem is on line 17 of your JSON. You've created an array called "grp_Account", so every item within that array needs to be a single value (such as another array or an object). However, on line 17 you have not a single value, but a name/value pair ("Grp_Carline_Collection": {...}).

Hope that helps!

Matt Doyle, Elated
28-Apr-11 16:07
Aw, this article was going so well until I got to the XML section. No one in their right mind would write XML like that! In XML, the element names themselves are the keys.

Something along these lines would be the correct way:

<shopperName>John Smith</shopperName>

<product id="34" quantity="1">SuperWidget</product>
<product id="56" quantity="3">WonderWidget</product>

This turns out to be 286 characters without spaces, as opposed to 236 for JSON. Not a huge difference. (Personally I still prefer JSON since it's dead simple to parse and work with in Javascript/PHP.)
28-Apr-11 19:20
@sockpuppet: Agreed. I was just trying to show the extreme case with XML. There are many ways to write XML, and there are also some cases where avoiding attributes makes sense. But in most situations I would definitely use your more compact version.

Here's a good discussion:


The point still stands though: JSON is generally more compact than XML.

Edit: I've added a note to the article to clarify. Thanks!

[Edited by matt on 28-Apr-11 19:36]

Matt Doyle, Elated
21-Apr-12 09:45
Matt ,

I love your tutorials man!

04-May-12 05:27
@tonyb67: Thanks

Matt Doyle, Elated
22-Mar-13 14:49
I was wondering if you can help with this. I am sending a jquery:

var jsonData = $.ajax({
type: "GET",
url: "",
async: false,
error: function(xhr, s, t) {
alert("xhr: " + xhr.status + " " + xhr.statusText + " " + s + " " + t);

but get an error. which is:
...NS_ERROR_FAILURE http://code.jquery.com/jquery-1.9.1.js
...send line 8526 data: no
It is failing in sending the request, looks like. Any clue
what could be wrong or how to fix the problem?
getdata.php simply reads a file in json syntax and sends
it back:


$string = file_get_contents("enroll-1.json");
echo $string;

If its' failing in the send then it can't be json syntax problem. It should at least send the request.
I ahve spent over 8 hours trygint to figure this out, any help
is greatly appreciated.



New posts
Old posts

Follow Elated