How to Read this JSON in PHP
up vote
-3
down vote
favorite
I have a simple JSON and want to read in PHP. I am certainly missing something in array, can anybody point out my mistake. Its been considerable time I am playing with this simple thing.
Here is the JSON & php :
$string='[
{
"phone":"+91009999000",
"name":"abcd",
"typeid":1
}
{
"phone":"+91009999222",
"name":"efg",
"typeid":2
}
{
"phone":"+91009999444",
"name":"hijhl",
"typeid":1
}
]';
$json_a = json_decode($string,true);
$phone = $json_a[0]['phone'];
$full_name=$json_a[0]['courseid'];
echo "phone = " . $phone;
echo "<br>fullname = " . $full_name;
php arrays json
add a comment |
up vote
-3
down vote
favorite
I have a simple JSON and want to read in PHP. I am certainly missing something in array, can anybody point out my mistake. Its been considerable time I am playing with this simple thing.
Here is the JSON & php :
$string='[
{
"phone":"+91009999000",
"name":"abcd",
"typeid":1
}
{
"phone":"+91009999222",
"name":"efg",
"typeid":2
}
{
"phone":"+91009999444",
"name":"hijhl",
"typeid":1
}
]';
$json_a = json_decode($string,true);
$phone = $json_a[0]['phone'];
$full_name=$json_a[0]['courseid'];
echo "phone = " . $phone;
echo "<br>fullname = " . $full_name;
php arrays json
use api.jquery.com/jquery.each
– Gulshan
Nov 19 at 12:38
4
you are missing commas in JSON string after each element (after closing curly brace)
– Eakethet
Nov 19 at 12:38
2
This is not a valid json
– pr1nc3
Nov 19 at 12:40
add a comment |
up vote
-3
down vote
favorite
up vote
-3
down vote
favorite
I have a simple JSON and want to read in PHP. I am certainly missing something in array, can anybody point out my mistake. Its been considerable time I am playing with this simple thing.
Here is the JSON & php :
$string='[
{
"phone":"+91009999000",
"name":"abcd",
"typeid":1
}
{
"phone":"+91009999222",
"name":"efg",
"typeid":2
}
{
"phone":"+91009999444",
"name":"hijhl",
"typeid":1
}
]';
$json_a = json_decode($string,true);
$phone = $json_a[0]['phone'];
$full_name=$json_a[0]['courseid'];
echo "phone = " . $phone;
echo "<br>fullname = " . $full_name;
php arrays json
I have a simple JSON and want to read in PHP. I am certainly missing something in array, can anybody point out my mistake. Its been considerable time I am playing with this simple thing.
Here is the JSON & php :
$string='[
{
"phone":"+91009999000",
"name":"abcd",
"typeid":1
}
{
"phone":"+91009999222",
"name":"efg",
"typeid":2
}
{
"phone":"+91009999444",
"name":"hijhl",
"typeid":1
}
]';
$json_a = json_decode($string,true);
$phone = $json_a[0]['phone'];
$full_name=$json_a[0]['courseid'];
echo "phone = " . $phone;
echo "<br>fullname = " . $full_name;
php arrays json
php arrays json
edited Nov 19 at 13:39
executable
964221
964221
asked Nov 19 at 12:36
Pratik
124
124
use api.jquery.com/jquery.each
– Gulshan
Nov 19 at 12:38
4
you are missing commas in JSON string after each element (after closing curly brace)
– Eakethet
Nov 19 at 12:38
2
This is not a valid json
– pr1nc3
Nov 19 at 12:40
add a comment |
use api.jquery.com/jquery.each
– Gulshan
Nov 19 at 12:38
4
you are missing commas in JSON string after each element (after closing curly brace)
– Eakethet
Nov 19 at 12:38
2
This is not a valid json
– pr1nc3
Nov 19 at 12:40
use api.jquery.com/jquery.each
– Gulshan
Nov 19 at 12:38
use api.jquery.com/jquery.each
– Gulshan
Nov 19 at 12:38
4
4
you are missing commas in JSON string after each element (after closing curly brace)
– Eakethet
Nov 19 at 12:38
you are missing commas in JSON string after each element (after closing curly brace)
– Eakethet
Nov 19 at 12:38
2
2
This is not a valid json
– pr1nc3
Nov 19 at 12:40
This is not a valid json
– pr1nc3
Nov 19 at 12:40
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
You are missing commas near curly braces.
It should be like this:
$string='[
{
"phone":"+91009999000",
"name":"abcd",
"typeid":1
},
{
"phone":"+91009999222",
"name":"efg",
"typeid":2
},
{
"phone":"+91009999444",
"name":"hijhl",
"typeid":1
}
]';
it's not a valid JSON format
– Gulshan
Nov 19 at 12:43
It is, because when you dojson_decode($string)
it will give output likeArray ( [0] => stdClass Object ( [phone] => +91009999000 [name] => abcd [typeid] => 1 ) [1] => stdClass Object ( [phone] => +91009999222 [name] => efg [typeid] => 2 ) [2] => stdClass Object ( [phone] => +91009999444 [name] => hijhl [typeid] => 1 ) )
– akshaypjoshi
Nov 19 at 12:44
@Gulshan this is valid JSON. What make you think this isn't valid?
– Cid
Nov 19 at 14:55
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
You are missing commas near curly braces.
It should be like this:
$string='[
{
"phone":"+91009999000",
"name":"abcd",
"typeid":1
},
{
"phone":"+91009999222",
"name":"efg",
"typeid":2
},
{
"phone":"+91009999444",
"name":"hijhl",
"typeid":1
}
]';
it's not a valid JSON format
– Gulshan
Nov 19 at 12:43
It is, because when you dojson_decode($string)
it will give output likeArray ( [0] => stdClass Object ( [phone] => +91009999000 [name] => abcd [typeid] => 1 ) [1] => stdClass Object ( [phone] => +91009999222 [name] => efg [typeid] => 2 ) [2] => stdClass Object ( [phone] => +91009999444 [name] => hijhl [typeid] => 1 ) )
– akshaypjoshi
Nov 19 at 12:44
@Gulshan this is valid JSON. What make you think this isn't valid?
– Cid
Nov 19 at 14:55
add a comment |
up vote
2
down vote
accepted
You are missing commas near curly braces.
It should be like this:
$string='[
{
"phone":"+91009999000",
"name":"abcd",
"typeid":1
},
{
"phone":"+91009999222",
"name":"efg",
"typeid":2
},
{
"phone":"+91009999444",
"name":"hijhl",
"typeid":1
}
]';
it's not a valid JSON format
– Gulshan
Nov 19 at 12:43
It is, because when you dojson_decode($string)
it will give output likeArray ( [0] => stdClass Object ( [phone] => +91009999000 [name] => abcd [typeid] => 1 ) [1] => stdClass Object ( [phone] => +91009999222 [name] => efg [typeid] => 2 ) [2] => stdClass Object ( [phone] => +91009999444 [name] => hijhl [typeid] => 1 ) )
– akshaypjoshi
Nov 19 at 12:44
@Gulshan this is valid JSON. What make you think this isn't valid?
– Cid
Nov 19 at 14:55
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
You are missing commas near curly braces.
It should be like this:
$string='[
{
"phone":"+91009999000",
"name":"abcd",
"typeid":1
},
{
"phone":"+91009999222",
"name":"efg",
"typeid":2
},
{
"phone":"+91009999444",
"name":"hijhl",
"typeid":1
}
]';
You are missing commas near curly braces.
It should be like this:
$string='[
{
"phone":"+91009999000",
"name":"abcd",
"typeid":1
},
{
"phone":"+91009999222",
"name":"efg",
"typeid":2
},
{
"phone":"+91009999444",
"name":"hijhl",
"typeid":1
}
]';
answered Nov 19 at 12:39
akshaypjoshi
539216
539216
it's not a valid JSON format
– Gulshan
Nov 19 at 12:43
It is, because when you dojson_decode($string)
it will give output likeArray ( [0] => stdClass Object ( [phone] => +91009999000 [name] => abcd [typeid] => 1 ) [1] => stdClass Object ( [phone] => +91009999222 [name] => efg [typeid] => 2 ) [2] => stdClass Object ( [phone] => +91009999444 [name] => hijhl [typeid] => 1 ) )
– akshaypjoshi
Nov 19 at 12:44
@Gulshan this is valid JSON. What make you think this isn't valid?
– Cid
Nov 19 at 14:55
add a comment |
it's not a valid JSON format
– Gulshan
Nov 19 at 12:43
It is, because when you dojson_decode($string)
it will give output likeArray ( [0] => stdClass Object ( [phone] => +91009999000 [name] => abcd [typeid] => 1 ) [1] => stdClass Object ( [phone] => +91009999222 [name] => efg [typeid] => 2 ) [2] => stdClass Object ( [phone] => +91009999444 [name] => hijhl [typeid] => 1 ) )
– akshaypjoshi
Nov 19 at 12:44
@Gulshan this is valid JSON. What make you think this isn't valid?
– Cid
Nov 19 at 14:55
it's not a valid JSON format
– Gulshan
Nov 19 at 12:43
it's not a valid JSON format
– Gulshan
Nov 19 at 12:43
It is, because when you do
json_decode($string)
it will give output like Array ( [0] => stdClass Object ( [phone] => +91009999000 [name] => abcd [typeid] => 1 ) [1] => stdClass Object ( [phone] => +91009999222 [name] => efg [typeid] => 2 ) [2] => stdClass Object ( [phone] => +91009999444 [name] => hijhl [typeid] => 1 ) )
– akshaypjoshi
Nov 19 at 12:44
It is, because when you do
json_decode($string)
it will give output like Array ( [0] => stdClass Object ( [phone] => +91009999000 [name] => abcd [typeid] => 1 ) [1] => stdClass Object ( [phone] => +91009999222 [name] => efg [typeid] => 2 ) [2] => stdClass Object ( [phone] => +91009999444 [name] => hijhl [typeid] => 1 ) )
– akshaypjoshi
Nov 19 at 12:44
@Gulshan this is valid JSON. What make you think this isn't valid?
– Cid
Nov 19 at 14:55
@Gulshan this is valid JSON. What make you think this isn't valid?
– Cid
Nov 19 at 14:55
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374825%2fhow-to-read-this-json-in-php%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
use api.jquery.com/jquery.each
– Gulshan
Nov 19 at 12:38
4
you are missing commas in JSON string after each element (after closing curly brace)
– Eakethet
Nov 19 at 12:38
2
This is not a valid json
– pr1nc3
Nov 19 at 12:40