Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
289 views
in Technique[技术] by (71.8m points)

c# - Extracting part of JSON response

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.

This JSON response is generated from the api.

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.

Any help will be much appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

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; }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...