When converting JSON to string (2nd method), I'm getting the error:
Newtonsoft.Json.JsonReaderException: 'Unexpected character encountered while parsing value: [. Path '', line 1, position 1.'
Why I'm getting an error in the 2nd method but the code is working fine in the 1st method, is there any solution for the 2nd method as I have to work with that method only?
Code:
static void Main(string[] args)
{
string abc = "[{\"provider\":\"test\",\"schemes\":[{\"tyo\":\"1\",\"check\":\"99\",\"slotNumber\":\"0\"},{\"tyo\":\"2\",\"check\":\"99\",\"slotNumber\":\"469\"}]}]";
var value = abc.FromJson().ToString();
// Getting error in below line
var value2 = abc.FromJson(typeof(String));
}
// First Method
public static object FromJson(this string json)
{
var value = JsonConvert.DeserializeObject(json);
return value;
}
// Second Method
public static object FromJson(this string json, Type type)
{
var value = JsonConvert.DeserializeObject(json, type);
return value;
}