提取JSON响应的一部分 [英] Extracting part of JSON response

查看:101
本文介绍了提取JSON响应的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编程新手.我目前正在使用地图功能,该功能要求我获取当前位置和最终位置之间的方向,但是我不知道如何从JSON响应中提取文本.

I am new in programming. I am currently working on a map function which requires me to get directions between current location and the final location, but I do not know how to extract the text from the JSON RESPONSE.

此JSON响应是从api生成的.

This JSON response is generated from the api.

这只是JSON响应的一部分.

This is only a part of the JSON response.

{
      "attributes" : {
        "length" : 0.094387438, 
        "time" : 0.2831, 
        "text" : "Go west on _________", 
        "ETA" : 1365037200000, 
        "maneuverType" : "esriDMTStraight"
      }, 
      "compressedGeometry" : "+1+t1b+170r-2f-a-e-2"
    }

我希望在显示的代码中提取文本",以将其显示在列表框中.

I wish to extract the "text" in the codes I show to display it on a listbox.

任何帮助将不胜感激.

推荐答案

您需要将JSON反序列化为C#类,可以使用 http://json2csharp.com/将为您提供RootObject类,从那里您可以访问text,该类将在名为text的属性下可用.

You need to deserialize your JSON to a C# class, You can use Newtonsoft JSON.NET Converters. To create a class that can hold your JSON object, you can copy your sample json and paste it in http://json2csharp.com/ that will give you the RootObject class, from there you can access the text, which would be available under property named text.

对于上面的JSON样本,您将得到一个类似的类:

For the above sampel JSON you would get a class like:

public class Attributes
{
    public double length { get; set; }
    public double time { get; set; }
    public string text { get; set; }
    public long ETA { get; set; }
    public string maneuverType { get; set; }
}

public class RootObject
{
    public Attributes attributes { get; set; }
    public string compressedGeometry { get; set; }
}

这篇关于提取JSON响应的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆