1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

JSON File

Discussion in 'PHP' started by ssimon171078, May 2, 2015.

  1. #1
    i have json file i want to print in php [title] replace the MGM lion with your pet or whoever
    i have json file:
    i tried to use foreach
    //foreach($obj as $result){
    //echo($result->gigs);
    //}
    stdClass Object ( [gigs] => Array ( [0] => stdClass Object ( [title] => replace the MGM lion with your pet or whoever [cached_slug] => replace-the-mgm-lion-with-
    your-pet-or-whoever-you-want [status] => approved [title_full] => replace the MGM lion with your pet or whoever [duration] => 4 [price] => $5 [price_i] => 5 [rating] => 10 [rating_count] => 10 [is_featured] => [gig_id] => 246395 [gig_url] => /rogh/replace-the-mgm-lion-with-your-pet-or-whoever-you-want?context=advanced_search&context_type=rating&pos=1&funnel=27e195fe-bd42-4f6c-a15a-b01aa28a085b [image_data] => stdClass Object ( [photo_file_name] => puppy_mgm_sized.jpg [title] => replace the MGM lion with your pet or whoever [cloud_img_base] =>
     
    ssimon171078, May 2, 2015 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    foreach ($obj['gigs'] as $gig) {
    echo $gig['title'];
    }

    Something like this?
     
    EricBruggema, May 3, 2015 IP
  3. Leela Narasimha

    Leela Narasimha Member

    Messages:
    14
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #4
    if you have json file. first read the json file
    $json_data = file_get_contents($json_file_name);
    $json_object = json_decode($json_data);

    $json_object will have std class objec which can be accessed by $json_object->title;

    If you want array instead of object then use
    $json_object = json_decode($json_data, TRUE);
     
    Leela Narasimha, May 4, 2015 IP