Hello everyone. I have some question about getting value to operate with from a return json.
To get json i used code like below
System.Net.WebRequest webreq = System.Net.WebRequest::Create("https://webservicesp.anaf.ro/PlatitorTvaRest/api/v3/ws/tva");
webresponse = webreq.GetResponse();
responsestr = webresponse.GetResponseStream();
reader = new System.IO.StreamReader(responsestr);
In the “info” at the end i have what i want want. A succesfull json.
But now i try to convert this into map, container or some type to operate with. Can you help me with that? Thanks allot
JSON is just a text file, therefore you could parse it by yourself. But the best code is what you don’t have to write, test and maintain, therefore it’s better to look for something existing.
One option is RetailCommonWebAPI::getMapFromJsonString().
Another is creating a .NET class representing the data in JSON (note that you can use Parse JSON as C# classes in Visual Studio) and use Newtonsoft.Json.JsonConvert::DeserializeObject() to deserialize the JSON string to an instance of the new class.
Great that you’r saying about RetailCommonWebAPI class. I’ve already tried with that, but have a problem.
map = RetailCommonWebAPI::getMapFromJsonString(reader.ReadToEnd());
I can’t find method which should i execute on the object with json(reader). When i pass the values to infobox - this is a reader.ReadToEnd() method and all json string display correctly
Edit: If someone have the same issue - you can execute ReadToEnd method only one time in object.
So it’s like this: RetailCommonWebAPI::getMapFromJsonString(reader.ReadToEnd()).
Then assing this to map and you can already operate on this