Json data isn't being parsed

I have the following JSON data and this is how it appears in the Visual Studio watch window:

"{\"TestResponse\":\"[{isValid:false,errorMessage:\'\',mainPath:~/yourName/yourfolder/,fileName:\'tempFile.txt\'}]\"}"

So I made two classes:

[System.Serializable]
public class ResponseData
{
    public bool isValid;
    public string errorMessage;
    public string mainPath;
    public string fileName;
}

[System.Serializable]
public class ResponseDataList
{
    public List<ResponseData> TestResponse;
}

And here’s how I’m parsing it:

ResponseDataList responseDataList = JsonUtility.FromJson<ResponseDataList >(jsonData);

I’m always getting zero elements in the responseDataList though. I tried changing the bool to a string, and the errorMessage to a character (because it looks like it an empty character '') but no luck.

With JsonUtility it seems to work with this:

string jsonData = "{\"TestResponse\":[{\"isValid\":true,\"errorMessage\":\"null\",\"mainPath\":\"path\",\"fileName\":\"fname\"}]}";

Here is a formatted overview:

{
  "TestResponse": [
    {
      "isValid": true,
      "errorMessage": "null",
      "mainPath": "path",
      "fileName": "fname"
    }
  ]
}

Well, like ranch000 pointed out your json is not valid json at all. The keys and also string values always have to be double quoted. No other quotes are allowed. Here’s a full description of the json format. Your string actually does represent valid json, but not what you think it contains. All you got is an object with a single key-value pair. Without all the backslash escaping your json looks like this:

{
    "TestResponse": "[{isValid:false,errorMessage:'',mainPath:~/yourName/yourfolder/,fileName:'tempFile.txt'}]"
}

So from the json’s point of view TestResponse is just a string, nothing else. The content of that string is not valid json, even when it wasn’t put into double quotes.

Like ranch000 said your actual json text should look like this

{
    "TestResponse": [
        {
            "isValid":false,
            "errorMessage":"",
            "mainPath":"~/yourName/yourfolder/",
            "fileName":"tempFile.txt"
        }
    ]
}

With backslash escaping and without the whitespace it should look like this

// C#
string jsonText = "{ \"TestResponse\": [{ \"isValid\":false, \"errorMessage\":\"\", \"mainPath\":\"~/yourName/yourfolder/\", \"fileName\":\"tempFile.txt\" }]}";

This should parse correctly with the classes you have there. If you got your “json” from a web service, the issue is most likely in that web service as the returned data is not in the format you expected.