Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/461.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 循环通过json对象、数组_Javascript_Php_Jquery_Json - Fatal编程技术网

Javascript 循环通过json对象、数组

Javascript 循环通过json对象、数组,javascript,php,jquery,json,Javascript,Php,Jquery,Json,我一直在尝试循环使用json对象,但似乎没有得到它。下面是json对象。它是一个json对象,将来自另一个站点,我想循环并获取一些详细信息 { "results" : [ { "address_components" : [ { "long_name" : "Jai Nagar Road", "short_name" : "Jai Nagar Road",

我一直在尝试循环使用json对象,但似乎没有得到它。下面是json对象。它是一个json对象,将来自另一个站点,我想循环并获取一些详细信息

    {
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "Jai Nagar Road",
               "short_name" : "Jai Nagar Road",
               "types" : [ "route" ]
            },
            {
               "long_name" : "Soorpur",
               "short_name" : "Soorpur",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Chittaurgarh",
               "short_name" : "Chittaurgarh",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "Rajasthan",
               "short_name" : "RJ",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "India",
               "short_name" : "IN",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "312023",
               "short_name" : "312023",
               "types" : [ "postal_code" ]
            }
         ],
         "formatted_address" : "Jai Nagar Road, Soorpur, Rajasthan 312023, India",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 25.0047284,
                  "lng" : 75.0057195
               },
               "southwest" : {
                  "lat" : 25.0006706,
                  "lng" : 75.0015796
               }
            },
            "location" : {
               "lat" : 25.0026729,
               "lng" : 75.00372419999999
            },
            "location_type" : "GEOMETRIC_CENTER",
            "viewport" : {
               "northeast" : {
                  "lat" : 25.0047284,
                  "lng" : 75.0057195
               },
               "southwest" : {
                  "lat" : 25.0006706,
                  "lng" : 75.0015796
               }
            }
         },
         "place_id" : "ChIJZW2OMHBTbzkRRo_IZ8-KtOc",
         "types" : [ "route" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Chainsingh Ji Ka Rajpura",
               "short_name" : "Chainsingh Ji Ka Rajpura",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Chittaurgarh",
               "short_name" : "Chittaurgarh",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "Rajasthan",
               "short_name" : "RJ",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "India",
               "short_name" : "IN",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "312023",
               "short_name" : "312023",
               "types" : [ "postal_code" ]
            }
         ],
         "formatted_address" : "Chainsingh Ji Ka Rajpura, Rajasthan 312023, India",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 25.0045601,
                  "lng" : 75.01064
               },
               "southwest" : {
                  "lat" : 24.98435,
                  "lng" : 74.99471989999999
               }
            },
            "location" : {
               "lat" : 24.9913835,
               "lng" : 74.99977579999999
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 25.0045601,
                  "lng" : 75.01064
               },
               "southwest" : {
                  "lat" : 24.98435,
                  "lng" : 74.99471989999999
               }
            }
         },
         "place_id" : "ChIJf8czVWNTbzkR8ZR9tJK11fY",
         "types" : [ "locality", "political" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "312023",
               "short_name" : "312023",
               "types" : [ "postal_code" ]
            },
            {
               "long_name" : "India",
               "short_name" : "IN",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "312023, India",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 25.134308,
                  "lng" : 75.2009999
               },
               "southwest" : {
                  "lat" : 24.8438019,
                  "lng" : 74.84139999999999
               }
            },
            "location" : {
               "lat" : 25.0362956,
               "lng" : 75.0143824
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 25.134308,
                  "lng" : 75.2009999
               },
               "southwest" : {
                  "lat" : 24.8438019,
                  "lng" : 74.84139999999999
               }
            }
         },
         "place_id" : "ChIJc0fixnhUbzkRWCXjs3L0pNw",
         "types" : [ "postal_code" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Chittaurgarh",
               "short_name" : "Chittaurgarh",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "Rajasthan",
               "short_name" : "RJ",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "India",
               "short_name" : "IN",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Chittaurgarh, Rajasthan, India",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 25.2151799,
                  "lng" : 75.81283000000001
               },
               "southwest" : {
                  "lat" : 24.20684,
                  "lng" : 74.10463
               }
            },
            "location" : {
               "lat" : 24.9560515,
               "lng" : 74.6868815
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 25.2151799,
                  "lng" : 75.81283000000001
               },
               "southwest" : {
                  "lat" : 24.20684,
                  "lng" : 74.10463
               }
            }
         },
         "place_id" : "ChIJmbw1Yl6gaDkRHM-dp2uZAa4",
         "types" : [ "administrative_area_level_2", "political" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Rajasthan",
               "short_name" : "RJ",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "India",
               "short_name" : "IN",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Rajasthan, India",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 30.1932842,
                  "lng" : 78.26338109999999
               },
               "southwest" : {
                  "lat" : 23.0632669,
                  "lng" : 69.484413
               }
            },
            "location" : {
               "lat" : 27.0238036,
               "lng" : 74.21793260000001
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 30.1932842,
                  "lng" : 78.26338109999999
               },
               "southwest" : {
                  "lat" : 23.0632669,
                  "lng" : 69.484413
               }
            }
         },
         "place_id" : "ChIJNw7j9_o-ajkR5YjABkWbK7U",
         "types" : [ "administrative_area_level_1", "political" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "India",
               "short_name" : "IN",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "India",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 35.5087008,
                  "lng" : 97.39535869999999
               },
               "southwest" : {
                  "lat" : 6.4626999,
                  "lng" : 68.1097
               }
            },
            "location" : {
               "lat" : 20.593684,
               "lng" : 78.96288
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 35.5087008,
                  "lng" : 97.39498069999999
               },
               "southwest" : {
                  "lat" : 6.7535159,
                  "lng" : 68.16288519999999
               }
            }
         },
         "place_id" : "ChIJkbeSa_BfYzARphNChaFPjNc",
         "types" : [ "country", "political" ]
      }
   ],
   "status" : "OK"
}
请让我知道是否有可能通过这个循环。我的问题是我想跟踪我的网站访问者。我想知道来访者的确切位置。
谢谢。

您想要什么样的输出数组?hi Siddiq,这是来自另一个页面的json响应,我只想循环并获取上面的格式化地址。“你好,穆罕默德,谢谢你的快速回复。但是我的问题是在第1页,我得到了用户cordinates,然后我通过get方法将用户cordinates发送到另一个页面(google),然后当响应以json形式出现时,此时我正在考虑循环使用该json,但由于某些原因我不知道。所以我发送到我的php页面,希望我能转换它,但我认为我走了一条漫长的道路。请告知我是否可以直接循环上面的json对象,而无需再次发送到php。。下面是我在页面上所做的乱七八糟的事情。$(文档).ready(函数(){$.get((data1){var rsp=data1;$.post(“jsontophp.php”),{rsp:rsp},函数(data){$(“#response”).text(data);});如果您想从jquery循环使用json,您可以做类似的事情。如果它不起作用,您面临什么问题?
// Yes you can apply the loop. First of all you need to decode JSON to an array.
$resultArray = json_decode($str,true);

foreach($resultArray as $row){
 .....

}