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?
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?
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", }, ] }
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
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
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
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.
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.
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" }] }] }
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']."
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.
$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.