Problem when deserializing JSON in dataSet

1

I am trying to deserialize a JSON result towards dataset . When trying to do it I throw the following error:

  

Additional text found in JSON string after finishing deserializing object. Path '[0].studentID' , line 1,

I do not see what additional text I may be getting from the JSON

These are the JSON data

[
    {
        "studentID": "[email protected]",
        "facultyID": "[email protected]",
    }
]

This is the class created

[Serializable]
class Parameters
{
     public string studentID { get; set; }
     public string facultyID { get; set; }
}

This is part of my code

IList<Parameters> searchResultsFromJason = new List<Parameters>();

string resultJSonRequest = "";

using (HttpWebResponse resp = req.GetResponse() as HttpWebResponse)

using (var reader = new StreamReader(resp.GetResponseStream()))
{
    var result = reader.ReadToEnd();

    string resultWebService = Convert.ToString(result);

    var JasonResultList = Newtonsoft.Json.JsonConvert.DeserializeObject<JToken>(resultWebService.ToString());

    resultJSonRequest = resultWebService;

    IList<JToken> results = JasonResultList.ToList();

    IList<Parameters> searchResults = new List<Parameters>();

    searchResultsFromJason = searchResults;

    foreach (JToken resultJAson in results)
    {
        Parameters searchResult = resultJAson.ToObject<Parameters>();
        searchResults.Add(searchResult);

    }
}

This is where the code falls and the error 'Additional text found in JSON string after finishing deserializing object. Path '[0].studentID', line 1,'

DataSet dataSet = JsonConvert.DeserializeObject<DataSet>(resultJSonRequest);
    
asked by user3790916 15.08.2018 в 16:56
source

1 answer

0

A DataSet is a representation of a database, that is, it can contain many tables, your origin json needs to indicate which table that arrangement belongs to, that is, your json should be something like that.

{
    "parameters": [
        {
            "studentID": "[email protected]",
            "facultyID": "[email protected]"      
        }
    ]
}

UPDATE:

If you necessarily need it in DataSet you must add the missing part, but you can bring it directly to the target object.

List<Parameters> parametros = JsonConvert.DeserializeObject<List<Parameters>>(resultJSonRequest);
    
answered by 15.08.2018 в 17:30