using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
public double Lat { get; set; }
public double Lng { get; set; }
public static void Test()
Console.WriteLine("Exception from old code: ");
public static void TestFix()
var obj = JObject.Parse(content);
var endLocationList = obj
.SelectTokens("routes[*].legs[*].steps[*].end_location")
.Select(t => t.ToObject<Location>())
Console.WriteLine("End locations using fixed code: ");
Console.WriteLine(JsonConvert.SerializeObject(endLocationList, Formatting.Indented));
public static void TestOld()
var obj = JObject.Parse(content);
string objRoutes = obj["routes"].ToString();
JArray routeArray = JArray.Parse(objRoutes);
JArray legArray = new JArray();
foreach (JObject item in routeArray)
string leg = item.GetValue("legs").ToString();
JArray stepArray = new JArray();
foreach (JObject item in legArray)
string step = item.GetValue("steps").ToString();
foreach (JObject item in stepArray)
string endLocation = item.GetValue("end_location").ToString();
Console.WriteLine(endLocation);
var json = @" { ""geocoded_waypoints"" : [
""geocoder_status"" : ""OK"",
""place_id"" : ""ChIJ5cGzCGa4yhQRk-lsJUoyizk"",
""types"" : [ ""street_address"" ]
""geocoder_status"" : ""OK"",
""place_id"" : ""ChIJb5VnEF64yhQRCrgps2g77jc"",
""types"" : [ ""street_address"" ]
""copyrights"" : ""Harita verileri ©2019 Google"",
""text"" : ""11 dakika"",
""end_address"" : ""Caferağa Mahallesi, Tuğlacı Eminbey Cd. No:5, 34710 Kadıköy/İstanbul, Türkiye"",
""start_address"" : ""Osmanağa Mahallesi, Serasker Cd. No:118, 34714 Kadıköy/İstanbul, Türkiye"",
""html_instructions"" : ""\u003cb\u003eZiya Bey Sk.\u003c/b\u003e adlı yerden \u003cb\u003eSerasker Cd.\u003c/b\u003e hedefine \u003cb\u003ekuzey\u003c/b\u003e yönünde ilerleyin"",
""points"" : ""kvdyFkqdpDGCMA?F""
""travel_mode"" : ""WALKING""
""html_instructions"" : ""\u003cb\u003eSerasker Cd.\u003c/b\u003e yönünde \u003cb\u003esola\u003c/b\u003e dönün"",
""maneuver"" : ""turn-left"",
""points"" : ""awdyFiqdpDMxAKr@OjACP[vCEPC^Cf@CLAHENMZ@LQf@Qd@KZENSj@""
""travel_mode"" : ""WALKING""
""html_instructions"" : ""\u003cb\u003eMühürdar Cd.\u003c/b\u003e yönünde \u003cb\u003esola\u003c/b\u003e dönün"",
""maneuver"" : ""turn-left"",
""points"" : ""{|dyFszcpDHFHF^X""
""travel_mode"" : ""WALKING""
""html_instructions"" : ""\u003cb\u003eMühürdar Cd.\u003c/b\u003e yönünde hafif \u003cb\u003esağa\u003c/b\u003e yönelin"",
""maneuver"" : ""turn-slight-right"",
""points"" : ""g{dyFiycpD?D?@?@@??@DB""
""travel_mode"" : ""WALKING""
""html_instructions"" : ""\u003cb\u003eMuvakkıthane Cd.\u003c/b\u003e konumunda \u003cb\u003esola\u003c/b\u003e dönün"",
""maneuver"" : ""turn-left"",
""points"" : ""_{dyFyxcpDDABA""
""travel_mode"" : ""WALKING""
""html_instructions"" : ""\u003cb\u003eMühürdar Cd.\u003c/b\u003e yönünde \u003cb\u003esağa\u003c/b\u003e dönün"",
""maneuver"" : ""turn-right"",
""points"" : ""uzdyF}xcpDhAz@pA|@pBtAHRJHRPPNPX\\d@BDHKfAlBDLDHDN@LBN""
""travel_mode"" : ""WALKING""
""html_instructions"" : ""\u003cb\u003eMühürdar Cd.\u003c/b\u003e boyunca ilerlemek için \u003cb\u003esola\u003c/b\u003e dönün"",
""maneuver"" : ""turn-left"",
""points"" : ""mkdyF_icpDNBJ@J@TBJ?JADA@DDN""
""travel_mode"" : ""WALKING""
""html_instructions"" : ""\u003cb\u003eMühürdar Cd.\u003c/b\u003e boyunca ilerlemek için \u003cb\u003esola\u003c/b\u003e dönün"",
""maneuver"" : ""turn-left"",
""points"" : ""ihdyFahcpDJEJAFALAH?VBj@F""
""travel_mode"" : ""WALKING""
""html_instructions"" : ""\u003cb\u003eTuğlacı Eminbey Cd.\u003c/b\u003e yönünde \u003cb\u003esola\u003c/b\u003e dönün"",
""maneuver"" : ""turn-left"",
""points"" : ""mddyFahcpDNg@""
""travel_mode"" : ""WALKING""
""traffic_speed_entry"" : [],
""overview_polyline"" : {
""points"" : ""kvdyFkqdpDUEM`B{@hHQfBGXMZ@Lc@lAQj@Sj@HFHF^X?D?B@@DBDABAhAz@bErCHRJHd@`@n@~@BDHKlAzBJXD\\ZD`@DVADA@DDNJERCVAbAJNg@""
""summary"" : ""Serasker Cd. ve Mühürdar Cd."",
""Yürüyerek gitmek için yol tarifi beta özelliğinde mevcuttur. Dikkat – Bu rotada kaldırım veya yaya yolu olmayabilir.""
public static void Main()
Console.WriteLine("Environment version: " + Environment.Version);
Console.WriteLine("Json.NET version: " + typeof(JsonSerializer).Assembly.FullName);
Console.WriteLine("Failed with unhandled exception: ");