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.
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; }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With