使用JS从Json获取值

时间:2014-01-14 21:07:43

标签: javascript

我需要知道如何做的方向:我在HiddenField值中保存,之后我使用JSON.parse:

[Object {LocationID = 102,LocationName =“9 47 Hall Street”,LocationLat =“40.69631”,更多...},对象{LocationID = 13,LocationName =“9090 Wilshire Blvd”,LocationLat =“34.0667” ,更多...},对象{LocationID = 12,LocationName =“9150 Wilshire-Palm Building”,LocationLat =“34.0669”,更多...},129更多...]

问题是我想循环json并获得类似的值

LocationLat =“40.69631”

LocationLng“= -73.96648”

之后我想要将值发送到GoogleMap JS函数

    function getValueFromList() {
        var jsonString = $get('<%= hfLocationList.ClientID %>').value;
        var json = JSON.parse(jsonString);
        for (i in json)  {
            var key = i;
            var val = json[i];

        }
    }

    function initialize() {
        var myLatlng = new google.maps.LatLng(34.052055, -118.460490);//sending the value to here
        var mapOptions = {
            zoom: 20,
            center: myLatlng
        }
        var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);

        var marker = new google.maps.Marker({
            position: myLatlng,
        });

        // To add the marker to the map, call setMap();
        marker.setMap(map);
    }

    google.maps.event.addDomListener(window, 'load', initialize);


************************VB Code*****************
 Public Sub GetLocationInfo()
        Dim LocationList As New List(Of LocationInfo)
        Dim dba As New DBAccess
        Dim ds As DataSet = dba.GetUserLocationsByID(m_User.UserID, m_User.UserID, m_User.CompanyCode)
        Dim dt As DataTable = ds.Tables(0)
        For Each dr As DataRow In dt.Rows()
            Dim locationInfo As New LocationInfo
            locationInfo.LocationName = dr("LocationName")
            locationInfo.LocationLat = dr("Lat")
            locationInfo.LocationLng = dr("lng")
            locationInfo.LocationID = dr("LocationID")
            LocationList.Add(locationInfo)
        Next

        Dim oSerilzer As New System.Web.Script.Serialization.JavaScriptSerializer
        Dim sJson As String = oSerilzer.Serialize(LocationList)
        hfLocationList.Value = sJson.ToString()
    End Sub

0 个答案:

没有答案