fork download
  1. <?php
  2. $json = '{
  3. "models":
  4. {
  5. "items":
  6. [
  7. {
  8. "id": 5086952,
  9. "name": "K&K УАЗ",
  10. "categoryId": 166068,
  11. "prices":
  12. {
  13. "max": "3437",
  14. "min": "1371",
  15. "avg": "2124",
  16. "curCode": "RUR",
  17. "curName": "руб."
  18. },
  19. "mainPhoto":
  20. {
  21. "url": "http://m...content-available-to-author-only...x.net/i?ctype=1&path=b0407143125_img_id2982751556581079079.jpg",
  22. "width": 700,
  23. "height": 660
  24. },
  25. "vendor": "K&K",
  26. "vendorId": 967139,
  27. "offersCount": 53,
  28. "isNew": 0,
  29. "rating": 4,
  30. "gradeCount": 20,
  31. "reviewsCount": 0,
  32. "link": "http://m...content-available-to-author-only...x.ru/model.xml?CMD=-RR=9,0,0,0-PF=1801946~EQ~sel~12129354-PF=2142397915~EQ~sel~1728823252-VIS=8070-CAT_ID=922145-EXC=1-PG=2&modelid=5086952&hid=166068",
  33. "isGroup": true,
  34. "modificationsCount": 1
  35. },
  36. {
  37. "id": 5087157,
  38. "name": "Replica B58",
  39. "categoryId": 166068,
  40. "prices":
  41. {
  42. "max": "10208",
  43. "min": "2850",
  44. "avg": "4774",
  45. "curCode": "RUR",
  46. "curName": "руб."
  47. },
  48. "mainPhoto":
  49. {
  50. "url": "http://m...content-available-to-author-only...x.net/i?path=b0903150122_img_id5220150240620638559.jpg",
  51. "width": 475,
  52. "height": 445
  53. },
  54. "vendor": "Replica",
  55. "vendorId": 967138,
  56. "offersCount": 1076,
  57. "isNew": 0,
  58. "rating": 5,
  59. "gradeCount": 30,
  60. "reviewsCount": 0,
  61. "link": "http://m...content-available-to-author-only...x.ru/model.xml?CMD=-RR=9,0,0,0-PF=1801946~EQ~sel~12129351-PF=2142397915~EQ~sel~1899859412-VIS=8070-CAT_ID=922145-EXC=1-PG=2&modelid=5087157&hid=166068",
  62. "isGroup": true,
  63. "modificationsCount": 27
  64. }
  65. ],
  66. "page": 1,
  67. "total": 13177,
  68. "count": 2
  69. }
  70. }';
  71. $my_obj = json_decode($json);
  72. #Array предметов в категории:
  73. var_dump($my_obj->models->items);
  74.  
  75. #Например стоимость.
  76. foreach ($my_obj->models->items as $item){
  77. echo "{$item->prices->avg} {$item->prices->curName}\n";
  78. }
  79. ?>
Success #stdin #stdout 0.02s 20520KB
stdin
Standard input is empty
stdout
array(2) {
  [0]=>
  object(stdClass)#3 (15) {
    ["id"]=>
    int(5086952)
    ["name"]=>
    string(10) "K&K УАЗ"
    ["categoryId"]=>
    int(166068)
    ["prices"]=>
    object(stdClass)#4 (5) {
      ["max"]=>
      string(4) "3437"
      ["min"]=>
      string(4) "1371"
      ["avg"]=>
      string(4) "2124"
      ["curCode"]=>
      string(3) "RUR"
      ["curName"]=>
      string(7) "руб."
    }
    ["mainPhoto"]=>
    object(stdClass)#5 (3) {
      ["url"]=>
      string(80) "http://m...content-available-to-author-only...x.net/i?ctype=1&path=b0407143125_img_id2982751556581079079.jpg"
      ["width"]=>
      int(700)
      ["height"]=>
      int(660)
    }
    ["vendor"]=>
    string(3) "K&K"
    ["vendorId"]=>
    int(967139)
    ["offersCount"]=>
    int(53)
    ["isNew"]=>
    int(0)
    ["rating"]=>
    int(4)
    ["gradeCount"]=>
    int(20)
    ["reviewsCount"]=>
    int(0)
    ["link"]=>
    string(169) "http://m...content-available-to-author-only...x.ru/model.xml?CMD=-RR=9,0,0,0-PF=1801946~EQ~sel~12129354-PF=2142397915~EQ~sel~1728823252-VIS=8070-CAT_ID=922145-EXC=1-PG=2&modelid=5086952&hid=166068"
    ["isGroup"]=>
    bool(true)
    ["modificationsCount"]=>
    int(1)
  }
  [1]=>
  object(stdClass)#6 (15) {
    ["id"]=>
    int(5087157)
    ["name"]=>
    string(11) "Replica B58"
    ["categoryId"]=>
    int(166068)
    ["prices"]=>
    object(stdClass)#7 (5) {
      ["max"]=>
      string(5) "10208"
      ["min"]=>
      string(4) "2850"
      ["avg"]=>
      string(4) "4774"
      ["curCode"]=>
      string(3) "RUR"
      ["curName"]=>
      string(7) "руб."
    }
    ["mainPhoto"]=>
    object(stdClass)#8 (3) {
      ["url"]=>
      string(72) "http://m...content-available-to-author-only...x.net/i?path=b0903150122_img_id5220150240620638559.jpg"
      ["width"]=>
      int(475)
      ["height"]=>
      int(445)
    }
    ["vendor"]=>
    string(7) "Replica"
    ["vendorId"]=>
    int(967138)
    ["offersCount"]=>
    int(1076)
    ["isNew"]=>
    int(0)
    ["rating"]=>
    int(5)
    ["gradeCount"]=>
    int(30)
    ["reviewsCount"]=>
    int(0)
    ["link"]=>
    string(169) "http://m...content-available-to-author-only...x.ru/model.xml?CMD=-RR=9,0,0,0-PF=1801946~EQ~sel~12129351-PF=2142397915~EQ~sel~1899859412-VIS=8070-CAT_ID=922145-EXC=1-PG=2&modelid=5087157&hid=166068"
    ["isGroup"]=>
    bool(true)
    ["modificationsCount"]=>
    int(27)
  }
}
2124 руб.
4774 руб.