I'm using NewtonSoft for json serialization of below-mentioned class
class SampleTest
{
public ArrayList tmpList = new ArrayList(3) { new Sample12 { a=2, b=3},
new Sample12 { a=45, b=5}, new Sample12 { a=2, b=3} };
}
class Sample12
{
public int a;
public int b;
}
Using below code for serialization and deserialization
var obj = new SampleTest();
string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
SampleTest deserializedobj = Newtonsoft.Json.JsonConvert.DeserializeObject<SampleTest>(jsonString);
Below is the json I'm getting.It's a valid JSON.
{ "tmpList":[
{
"a":2, "b":3 }, {
"a":45, "b":5 }, {
"a":2, "b":3 } ] }
While deserializing the JSON, I'm getting 6 records instead of 3 records. Out of that 3 are the valid object and remaining 3 are invalid JSON (JSON enclosed in curly braces)
Below one is one of the invalid JSON,
{{ "a": 2, "b": 3 }}
Why the last 3 records are added up while deserializing and How can I get rid of those 3 records? Is there any way to deserialize the last 3 records?