- Home /
JSON invalid value
Hi all,
By using Unity JSON utility, is there a way to check if json is valid?
I want to do something like this but have no idea how to check if json is valid
string json = wr.downloadHandler.text;
if(json.isvalid){
jsonObject obj = JsonUtility.FromJson<jsonObject >(json );
}
else{
// Handle error here
}
Can someone guide me or shine a bit of light on this?
Thank you
Answer by xxmariofer · Nov 23, 2020 at 08:40 AM
There is not a valid property because it depends if you try to cast it to a jsonObject will work but if you cast it to another type it will not, so there is no a simply "general" way of knowing if the json is valid
string json = wr.downloadHandler.text;
jsonObject obj = JsonUtility.FromJson<jsonObject >(json );
if(obj == null)
{
// Handle error here
}
Your answer
Follow this Question
Related Questions
[JsonUtility] cannot deserialize json to new instances of type X 2 Answers
Deserialize Json into list.,how to deserialize a list via .FromJson 1 Answer
Json.net deserialization problem 1 Answer
Deserializing dictionary with 'Json.Net' for Unity returns a null object. 0 Answers
JSON deserialization 0 Answers