Decode specific Json

I'm trying decode a json, using json_decode. I need get only 2 informations of json: title and id.

This informations are related to product. But my problem is, "inside of" each Product, have images and each image have a title also.

My doubt is: how get "title" (only related to product)?

Code at the moment:

$result = curl_exec($ch); $jsonIterator = new RecursiveIteratorIterator( new RecursiveArrayIterator(json_decode($result, TRUE)), RecursiveIteratorIterator::SELF_FIRST); foreach ($jsonIterator as $key => $val) { echo $val['title']; }

JSON example:

http://freetexthost.com/kfoki4cy03

-------------Problems Reply------------

You don't need to use RecursiveIteratorIterator at all. Because json_decode() with the second parameter == true gives back an associative array, simply traverse it like so:

$json = json_decode($result, true);
if (is_array($json) && count($json)
&& is_array($json['products']) && count($json['products']))
{
foreach($json['products'] as $aProduct)
{
$id = $aProduct['id'];
$title = $aProduct['title'];

...
}
}

Category:php Views:2 Time:2019-02-10
Tags: php json

Related post

  • How to decode a JSON string in PHP? 2009-08-12

    I have a JSON string that looks something like this: {"addresses":{"address":[{"@array":"true","@id":"888888","@uri":"xyz","household":{"@id":"44444","@uri":"xyz"},"person":{"@id":"","@uri":""},"addressType":{"@id":"1","@uri":"xyz","name":"Primary"},

  • How to decode a JSON String 2010-03-30

    everybody! Could I ask you to help me to decode this JSON code: $json = '{"inbox":[{"from":"55512351","date":"29\/03\/2010","time":"21:24:10","utcOffsetSeconds":3600,"recipients":[{"address":"55512351","name":"55512351","deliveryStatus":"notRequested

  • How to decode a json string with gson in java? 2011-05-21

    I have a json string (the stream of social network Qaiku). How can I decode it in Java? I've searched but any results work for me. Thank you. --------------Solutions------------- As an example using Gson, you could do the following Gson gson = new Gs

  • How to convert a List to specific Json format 2011-08-17

    I want to be able to convert a List<T> into a specific JSON table-like format. In my case, the T will always be a simple object (no nested properties). Here are two examples to illustrate what I want. Example #1: List<Person> to JSON // C

  • How to decode a JSON string using C#? 2011-10-08

    I'm looking for an example code/lib to decode a JSON string using C#. to decode I can do this: var data = new Dictionary<string,string>(); data.Add("..", "..."); var json_encoded = new JavaScriptSerializer().Serialize(data); but to decode, How

  • How would I decode a JSON encoded array of values and use it? 2011-03-09

    I currently have created the following JSON output from the database into a mini API running on my site. I am trying to utilize this API, but I am unsure how. Here's the resulting JSON of an example query: { "uploads":[ { "upload":{ "id":"74", "uploa

  • decoding the JSON output from Microsoft translator API with PHP 2011-08-06

    this issue seems specific to microsofttranslator.com so please ... any answers, if you can test against it ... Using the following URL for translation: http://api.microsofttranslator.com/V2/Ajax.svc/TranslateArray .. I send via cURL some fantastic ar

  • Internal server error while decoding a json file 2012-02-28

    I'm opening a JSON file and decoding the content of it, so I can insert the content into my database using MySQL: [{"publisher": "some publisher", "img": "url to image", "title": "some title", "platform": "some platform", "year": "2012", "genre": "so

  • Decode complex JSON in Python 2009-08-04

    Hey, I have a JSON object created in PHP, that JSON object contains another escaped JSON string in one of it's cells: php > $insidejson = array('foo' => 'bar','foo1' => 'bar1'); php > $arr = array('a' => array('a1'=>json_encode($ins

  • how to decode this JSON string? 2010-02-10

    this is what i get as a string from a feed finder url (JSON Encoded): {"updated":1265787927,"id":"http://www.google.com/reader/api/0/feed-finder?q\u003dhttp://itcapsule.blogspot.com/\u0026output\u003djson","title":"Feed results for \"http://itcapsule

  • How do I call and decode a JSON web service from PHP? 2010-07-07

    From within PHP, how can I call an external JSON web service and then decode the returned string? For example (pseudo-code): <?php $var jsonStr = json_decode("http://maps.google.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain

  • How can I access a specific json object using jquery and json? 2010-07-08

    I'm having a problem trying to return a specific record using jQuery and JSON. I'm passing a variable to the function and want to output only the data matching the id I've set when the function is executed. Right now, my function looks like this: fun

  • PHP decode nested JSON 2010-08-24

    I've a nested JSON code as (it's actually my facebook status updates) { "data": [ { "id": "1290561400000000", "from": { "name": "My name", "id": "500920000" }, "message": "Message body", "updated_time": "2010-08-24T08:22:13+0000", "comments": { "data

  • Problem with decoding unicode JSON in perl 2011-04-04

    I experience a strange behavior in Perl while trying to decode a Unicode JSON string coming from a PHP script's json_encode function. I simplified the problem to next code: #!/usr/bin/perl use CGI; use JSON; print CGI::header(-type=>'text/html', -

  • not able to call methods after decoding from json 2011-05-13

    I have a Lua class like below. I am using json to serialize the object and put it in a key value store. I am able to serialize the object and put it in the key value store successfully but i am not able to call any methods of the object after i retri

  • What am I missing to decode a JSON bool using JSONKit for IPhone 2011-08-12

    I have a REST endpoint that returns a BOOL value depending on whether or not the server operation was successful. It returns the response body as simply true or false When I try to decode the value from the server, I get the following error: Unexpect

  • How to decode a json data array? 2011-08-16

    The json data object below is what's returned from a custom Google search API request. I need to extract each of the "url" elements and place them into an array (using PHP). myArray = {url1, url2, url3, etc...} How? data = '{ "responseData": { "resul

  • Javascript Object to Json. PHP can't decode serialized JSON 2011-09-16

    I have a javascript object which I am encoding to Json and sending data to PHP. Unfortunately, PHP can't decode JSON string to array. I am lost at this point. Jquery sendData = {city: 48, fullName: 'John'}; sendData = JSON.stringify(sendData); $.get(

  • Accessing specific JSON value 2011-10-05

    I currently have a variable $return which contains JSON-encoded data, which prints out as: ({0:{data:[[0, null], [1, null], [2, null], [3, null], [4, null], [5, null], [6, null], [7, null], [8, null], [9, null], [10, null], [11, null], [12, null], [1

  • Encoded/serialization Json syntax vs. decoded/deserialized Json syntax 2011-10-21

    I'm new to working with Json strings and am not really sure if the JsonTextDecode block on the AppInventor works correctly, because the input and the result seems the same to me... So by the way, what exactly is correct? encode or serialize and decod

  • Associative array decoding in JSON 2011-11-03

    I am trying to change the class of a list of elements based on information in a DB. I figure the easy way was via an array. I build the array on the php side as follows. $setClassResult = array(); while($row = mysql_fetch_array( $result )) { $setClas

  • Appengine ProtoRPC can't decode my JSON 2012-03-26

    Can't seem to get protoRPC API on app-engine to work for me. This is my request: $.ajax({ url: '/guestRPC.get_tags', type: 'POST', contentType: 'application/json', dataType: 'json', data: { prefix: JSON.stringify(request), locale: JSON.stringify('{{l

  • PHP decode data JSON/SERIALIZED 2012-03-28

    I cant get this into an array.. I should decode this with php: ({serverTimestamp: "Wed, 28 Mar 2012 11:40:26 +0000",users: [{userId: "username",statuscode:0,floatingPL:-1000.00,balance:50000,equity:40000,freeMargin:4000,marginInUse:30.11,currency:"EU

  • Why does SJCL report "this is not JSON" when trying to decode this JSON snippet? 2012-04-26

    I'm using SJCL, and it works fine with small ASCII strings. But when I try to decode this piece of JSON (the result of the encryption of an HTML page) I get a "this is not JSON!" error. The JSON has been produced by SJCL, and while I did encode it an

  • How to decode a JSON value that can be a String or null? 2015-01-19

    I am trying to decode JSON in Rust. JSON examples: [{"id": 1234, "rank": 44, "author": null}] [{"id": 1234, "rank": 44, "author": "Some text"}] If I use String for the author field: #[derive(Show, RustcDecodable, RustcEncodable)] pub struct TestStruc

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.131 (s). 11 q(s)