-3

i got json data from tripadvisor here's example of tripadvisor json with addrees : http://api.tripadvisor.com/api/partner/2.0/map/-6.138235729678662,106.82242203190232?key=5a4401fbeeaf472ca5143d4(screet)&q=Ibis+Mangga+Dua+Hotel

      {
        "data": [
           {
            "see_all_photos": "http://www.tripadvisor.com/LocationPhotos-g294229-d299539-m22657-Ibis_Jakarta_Mangga_Dua_Hotel-Jakarta_Java.html",
           "web_url": "http://www.tripadvisor.com/Hotel_Review-g294229-d299539-Reviews-m22657-Ibis_Jakarta_Mangga_Dua_Hotel-Jakarta_Java.html",
          "percent_recommended": 52,
            "location_string": "Jakarta, Java",
      "location_id": "299539",
       "write_review": "http://www.tripadvisor.com/UserReview-g294229-d299539-m22657- Ibis_Jakarta_Mangga_Dua_Hotel-Jakarta_Java.html",
      "price_level": "$",
      "api_detail_url": "http://api.tripadvisor.com/api/partner/2.0/location/299539?key=5a4401fbeeaf472ca51",
      "address_obj": {
        "street1": "Jalan Pangeran Jayakarta 73",
        "street2": "",
        "city": "Jakarta",
        "state": null,
        "country": "Indonesia",
        "postalcode": "10730",
        "address_string": "Jalan Pangeran Jayakarta 73, Jakarta 10730 Indonesia"
       },
      "distance": ".49",
       "category": {
        "name": "hotel",
        "localized_name": "Hotel"
       },
       "awards": [],
      "subcategory": [
        {
          "name": "hotel",
          "localized_name": "Hotel"
        }
       ],
        "num_reviews": "287",
       "rating_image_url": "http://www.tripadvisor.com/img/cdsi/img2/ratings/traveler/3.0-22657-5.png",
       "name": "Ibis Jakarta Mangga Dua Hotel",
       "ancestors": [
          {
           "abbrv": null,
           "level": "City",
           "name": "Jakarta",
           "location_id": "294229"
         },
         {
           "abbrv": null,
           "level": "Region",
            "name": "Java",
           "location_id": "294228"
         },
         {
           "abbrv": null,
           "level": "Country",
           "name": "Indonesia",
           "location_id": "294225"
         }
        ],
        "bearing": "southeast",
        "longitude": "106.82842",
        "rating": "3.0",
        "latitude": "-6.14201",
        "ranking_data": {
         "geo_location_id": "294229",
         "ranking_string": "#122 of 322 hotels in Jakarta",
         "geo_location_name": "Jakarta",
         "ranking_out_of": "322",
          "ranking": "122"
        }
      }
     ],
   "paging": {
    "previous": null,
     "skipped": "0",
     "results": "1",
     "next": null,
      "total_results": "1"
   }
   }

it's similar with this code : loading data with json and jquery

 function loadFlickr(flickrid)
 {
 // Display a loading icon in our display element
  $('#feed').html('<span><img src="/blog/images/lightbox-ico-loading.gif" alt="">    </span>');
 // Request the JSON and process it
 $.ajax({
 type:'GET',
 url:"http://api.flickr.com/services/feeds/photos_public.gne",
 data:"id="+flickrid+"&lang=en-us&format=json&jsoncallback=?",
 success:function(feed) {
 // Create an empty array to store images
 var thumbs = [];
 // Loop through the items
 for(var i=0, l=feed.items.length; i < l && i < 16; i)
 {
 // Manipulate the image to get thumb and medium sizes
 var img = feed.items[i].media.m.replace(
 /^(.*?)_m.jpg$/,
 '<a href="/blog/$1.jpg"><img src="/blog/$1_s.jpg" alt=""></a>'
  );
 // Add the new element to the array
 thumbs.push(img);
 }
 // Display the thumbnails on the page
 $('#feed').html(thumbs.join(''));
 // A function to add a lightbox effect
 addLB();
  },
 dataType:'jsonp'
  });
  } 

call function

loadFlickr("29080075@N02");

how i can save to array with java script or jquery and i will use the array for print screen

thanks before

Cute Chenz
  • 11
  • 4
  • What have you tried so far? Where have you looked for solutions to your problem? – Jonast92 Oct 27 '14 at 10:37
  • 1
    You shouldn't convert a JSON object to Array, it doesn't make much sense... Why don't you use JSON object directly? – MarcoS Oct 27 '14 at 10:38

4 Answers4

1

store the json object in a varable -

$str //your json string

var_dump(json_decode($str, true));
Sougata Bose
  • 31,517
  • 8
  • 49
  • 87
0

Save it into a variable with

   var myArray = JSON.parse(Yourvariablecontainingjson); 

w3schools eplanation

Sjoerd de Wit
  • 2,353
  • 5
  • 26
  • 45
0
var string = JSON.stringify( object );
var object = JSON.parse( string );
  • 2
    Please edit your answer to add an explanation of how your code works and how it solves the OP's problem. Many SO posters are newbies and will not understand the code you have posted. – i alarmed alien Oct 27 '14 at 11:08
-1

Just use json_encode($variableContainingtheupperJsonCode). It will return you an array.