I use WebClient in first time. And when I do the following
var raw = new WebClient().DownloadString("http://ip-api.com/json");
and just test-method show it normally in browser as string:
public string GetLocationData()
{
var raw = new WebClient().DownloadString("http://ip-api.com/json");
return raw;
}
However, real-need method returns with extra backslashes
public ActionResult GetLocationDataInJson()
{
return Json(GetLocationData(), JsonRequestBehavior.AllowGet);
}
returns me
"{\"as\":\"AS6584 Microsoft Corporation\",\"city\":\"Dublin\",\"country\":\"Ireland\",\"countryCode\":\"IE\",\"isp\":\"Microsoft Limited\",\"lat\":53.3331,\"lon\":-6.2489,\"org\":\"Microsoft Corporation\",\"query\":\"194.69.98.180\",\"region\":\"L\",\"regionName\":\"Leinster\",\"status\":\"success\",\"timezone\":\"Europe/Dublin\",\"zip\":\"\"}"
So I can't use this data to proccess via MicrosoftJson. How can I get normal Json data? I tried String.Replace()
but it doesnt work.
Updates : the same happens when I try to send my raw string to another method
public class LocationData
{
public LocationData(string json)
{
JObject jObject = JObject.Parse(json);
JToken location = jObject["LocationData"];
Latitude = (string)location[@"lat"];
Longitude = (string)location[@"lon"];
}
public string Latitude { get; set; }
public string Longitude { get; set; }
}
it throw an exception and says that can't find "lat" or "lon"; Debugger shows this input string in constructor method of LocationData with backslashes.
I read another questions about verbatim string and usage of "@". It doesn't work.