How to check a JSON object?

I want to check the correctness of the incoming json object on the server side. Is there a standard / optimal way to do this? What is your approach to validation?

+3
source share
2 answers

My advice is to deserialize JSON and see if it breaks. For example, if you use C # on the server side, you can use newfangled DataContractJsonSerializeror do it the old way with JavaScriptSerializer, which is probably a lot easier.

var serializer = new JavaScriptSerializer();
var result = serializer.Deserialize<Dictionary<string, object>>(jsonString);

EDIT: And now, when it turns out that you are using Java, of course my C # example will not work for you, but the concept is the same. Stackoverflow already has some answers here : Convert JSON string to Java ME object?

+5

JSON. , , , .

+3

Source: https://habr.com/ru/post/1794325/


All Articles