Instead of echoing out your html from your PHP file you can use knockoutjs or angularjs to display your json object on the front end which is better practice and your page will load faster.
What if server send JSON in another format i.e. with different array (not movies)? Then it shows an error. I got this type of problem. Is there any solution for that?
Friend i want to get data from api url against a specific id ... i want to get only that movie hows id is 1 not want to get all movies ??? kindly tell me
what if we donot want to access json object from a file? I mean we can return json object using this statement return response()->json([ ]); How to parse it in php?
hi Traversy media .. what if you want to click a link and assign the id to the link , and every time you click the link it will show the data of the id.. example: { "sample":[ "id": "1", "data":{ " sample": "test123", "example": "test456", }, ] }
How do you get values from nested arrays? I can echo prod_name, but i can't echo file_url within and item_price. { "products" : [{ "prod_name" : "Towel", "media" : [{ "file_url" : "site.com/img.jpg" }], "pricing" : [{ "item_price" : "200" }] }] }
Thaks for your videos, I have my Json data in mysql database, can you instruct me how can I get and write data in Json field. for example my user datasuch as name, lastname and address are in meta field
but why we are using Json ? i learning json just for study perpose that's why i wanna to clear my point with know power of json ? how is it useful for me as php programmer ?
You can share data between applications, all they need to know is how to read and write json files. In an e-commerce environment you can use standardised json files to get live information from various hotels etc re bookings and rooms, and use the data to build a comparison site; how powerful your comparison site is will depend on how good you are at processing arrays and the content of those json files. In a specific php application you could use json files to store default start-up configuration data. Try your hand with Composer, getcomposer.org, it uses a composer.json file to configure and update web applications that rely on third-party packages.
Hello, thanks a lot for this tutorial. Has helped me a lot. One more thing though, How can i save decoded data into my mysql database? I can display it, thanks to your video, but how can i store that data into my db. Thanks
$jsondata = file_get_contents("movies.json"); echo $jsondata; $decoded_json = json_decode($jsondata,true); echo $decoded_json['movies'][0]['title']; // not working What am I doing wrong here? I don't get any output from the second echo.
This is only useful for a flat json file. Most json that you will be working with will not be flat, but actually have multiple dimensions, and there will be times when you won't know the depth of the json you're working with.
am not getting the correct output. this is the thing which get display. can someone help me, wat amd doing wrong."; foreach($json['movies'] as $movie){ $output .= " ".$movie['title']." "; $output .=" Year: ".$movie['year']." "; $output .=""; $output .=""; } $output .=""; echo $output; ?> Genre: ".$movie['genre']." Starting: ".$movie['starting']."
json beginner here. very helpful! been stuck for over a day now on parsing an array in json into php. this solved every question i had!
lol several years later & this tut was still helpful. Helped me on pulling info from an Xbox Api
Thanks for the awesome video, still helps 8 years later :D
Instead of echoing out your html from your PHP file you can use knockoutjs or angularjs to display your json object on the front end which is better practice and your page will load faster.
Thank you a lot, I am a newbie in php and this is what i really wanted simple and straight foward, TUMBS-UP
Thanks for this! One question, what if I have two or more Json files that I want to parse on the same page?
Nice video...
Thank you. Great demonstration of basics!
thanks a million best explanation I've come across
What if server send JSON in another format i.e. with different array (not movies)? Then it shows an error. I got this type of problem. Is there any solution for that?
very useful information
Tnx :)
can you show how to parse m3u file and output it into xls or json or xml?
Brad, If I wanted to put the json information in an html table that already has style, what would that be with this code?
Friend i want to get data from api url against a specific id ... i want to get only that movie hows id is 1 not want to get all movies ??? kindly tell me
awsome,,,, 20th video i tried and only one to show how to echo the nested elements... if only found this 3 hours ago
You now need a . In between the html and php. object.= “”.$movie[]…
Hi. Can you make a tutorial on how to convert json data into image? JSON file should not be pre-defined, if possible. :|
What does true as the second argument in json_decode do?
What if i would like to add pagination ?
what if we donot want to access json object from a file? I mean we can return json object using this statement
return response()->json([ ]); How to parse it in php?
Thank you, this was a great intro, helped a lot :)
hi Traversy media .. what if you want to click a link and assign the id to the link , and every time you click the link it will show the data of the id.. example:
{
"sample":[
"id": "1",
"data":{
" sample": "test123",
"example": "test456",
},
]
}
Muchos gracias!
woow thank you very much ❤❤❤❤
Hello Brad, can you show us how to navigate next and previous through $JSON['movies']? Thanx in advance.
Thanks for this. Very helpful! :)
How do you get values from nested arrays? I can echo prod_name, but i can't echo file_url within and item_price.
{
"products" : [{
"prod_name" : "Towel",
"media" : [{
"file_url" : "site.com/img.jpg"
}],
"pricing" : [{
"item_price" : "200"
}]
}]
}
What if I want to paginate it after retrieving data from my JSON?
aaaaaayyynd
How do I do this with a json file over the internets?
$url = 'YourURLHere';
$jsondata = file_get_contents($url);
$json = json_decode($jsondata, true);
Please also explain how to fetch image and vedio .
Thaks for your videos,
I have my Json data in mysql database, can you instruct me how can I get and write data in Json field. for example my user datasuch as name, lastname and address are in meta field
Warning: Invalid argument supplied for foreach() in /Applications/MAMP/htdocs/json/index.php on line 7
The same with me... no solution around de internet yet.
Finally the solution! We need save the data on a encoding file like UTF-8... and voilá! =)
but why we are using Json ? i learning json just for study perpose that's why i wanna to clear my point with know power of json ? how is it useful for me as php programmer ?
Hardeep Singh It lets you parse data in an easy and quick way.
You can share data between applications, all they need to know is how to read and write json files.
In an e-commerce environment you can use standardised json files to get live information from various hotels etc re bookings and rooms, and use the data to build a comparison site; how powerful your comparison site is will depend on how good you are at processing arrays and the content of those json files.
In a specific php application you could use json files to store default start-up configuration data. Try your hand with Composer, getcomposer.org, it uses a composer.json file to configure and update web applications that rely on third-party packages.
Hello, thanks a lot for this tutorial. Has helped me a lot. One more thing though, How can i save decoded data into my mysql database? I can display it, thanks to your video, but how can i store that data into my db. Thanks
Many thanks , great tutorial
$jsondata = file_get_contents("movies.json");
echo $jsondata;
$decoded_json = json_decode($jsondata,true);
echo $decoded_json['movies'][0]['title']; // not working
What am I doing wrong here? I don't get any output from the second echo.
You saved my life thanks
how to get JSON data from the server. . . Pls.
This is only useful for a flat json file. Most json that you will be working with will not be flat, but actually have multiple dimensions, and there will be times when you won't know the depth of the json you're working with.
Thank you!
That was awesome, I love you, man!
Awesome thank you.
how would you wrap the data in html markup? not inside an echo string
here is a paste example bpaste.net/show/CFOrx5Gf4VHM40yuCwRI/
Thanks *****
+Brad Traversy how to make load data with jquery ajax for peformance fastest load page?
No bullshit, I like it :)
Nice video !!! Can you share us the source code please ?
am not getting the correct output. this is the thing which get display. can someone help me, wat amd doing wrong."; foreach($json['movies'] as $movie){ $output .= "
".$movie['title']."
"; $output .="
Year: ".$movie['year']."
"; $output .=""; $output .=""; } $output .=""; echo $output; ?>
Genre: ".$movie['genre']."
Starting: ".$movie['starting']."
Dinesh H Try that:
foreach ($json['actionHolder'][0]['intervalMileage'] as $main){
$output .= '';
$output .= ''.$main['intervalMileage'].'';
$action .= ''.$main['action'].'';
$output .= '';
}
Thanks Brad, it so useful :)
Big help, thanks! :)
👍
just watched this on seepd 2
just for tips n tricks
you can drag your files if you want to open them, for example in your browser (Chrome) or Sublime
not worked error for foreach !~!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Gracias Senor
Healthcare API connection successful/parsed
Thaanks that's helped me !
What about if my data from mysql ?