3

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.

2 Answers 2

3

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; }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks it helps a lot, but how do I call the "text" property and display it in a list box? I'm poor in programming
0

refer this links.hope it will helps u to sortout ur issue

refer link 01

refer link 02

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.