从多维json对象获取数据

时间:2015-05-06 16:40:43

标签: javascript jquery json

我正在尝试获取google驾驶api返回的以下json对象的结果。

public class Step
{
    List<Task> tasks;

    public void AddTask(Task t)
    {
        t.StatusChanged += HandleStatusChanged;
    }

    private void HandleStatusChanged(object sender, TaskStatusEventArgs args)
    {
        string taskName = args.TaskName;
        TaskStatus status = args.Status;

        TripleLogic(taskName, status);
    }
}

我将如何获取“text”或“end_address”中的数据

我试过了

EventHandler<TEventArgs>

"routes": [
    {
        "bounds": {
            "Ga": {
                "C": 39.01115,
                "j": 39.06483
            },
            "xa": {
                "j": -77.57857000000001,
                "C": -77.47601
            }
        },
        "copyrights": "Map data ©2015 Google",
        "legs": [
            {
                "distance": {
                    "text": "9.4 mi",
                    "value": 15096
                },
                "duration": {
                    "text": "15 mins",
                    "value": 870
                },
                "end_address":"1234 Any St USA".....//and so on

我得到了

 alert(result.routes.legs.distance.text)

 alert(result.routes.legs.end_address);
分别

1 个答案:

答案 0 :(得分:3)

routes是一个数组,legs是每个routes数组对象中的数组

尝试

 alert(routes[0].legs[0].distance.text)