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;









share|improve this question
























  • 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















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;









share|improve this question
























  • 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













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;









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • 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












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
}
]';





share|improve this answer





















  • 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










  • @Gulshan this is valid JSON. What make you think this isn't valid?
    – Cid
    Nov 19 at 14:55











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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

























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
}
]';





share|improve this answer





















  • 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










  • @Gulshan this is valid JSON. What make you think this isn't valid?
    – Cid
    Nov 19 at 14:55















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
}
]';





share|improve this answer





















  • 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










  • @Gulshan this is valid JSON. What make you think this isn't valid?
    – Cid
    Nov 19 at 14:55













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
}
]';





share|improve this answer












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
}
]';






share|improve this answer












share|improve this answer



share|improve this answer










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


















  • 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










  • @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


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

To store a contact into the json file from server.js file using a class in NodeJS

Redirect URL with Chrome Remote Debugging Android Devices

Dieringhausen