I'm trying to understand Json. Easy object and string - it's clear. What about objects like
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using State;
using System.IO;
namespace JSON
{
[Serializable]]
class Top{
public int I = 0;
public List<Q> lst = new List<Q>();
public Top() { lst.Add(new Q()); }
}
[Serializable]
class Q {
int i1 = 100500;
string s1 = "abrakadabra";
List<A> aList = new List<A>();
public Q() { aList.Add(new A()); }
}
[Serializable]
class A {
string text = "secret will of my Dad";
}
class Program
{
static void Main(string[] args)
{
Top exam = new Top();
string DataString = JsonConvert.SerializeObject(exam);
JsonSerializer serializer = new JsonSerializer();
TextWriter tw = new StreamWriter("test.txt");
serializer.Serialize(tw, exam);
tw.Flush();
tw.Close();
sw.Close();
}
}
}
Would it be able to enline in Json string such structure of a C# object, and then, to build it inside Java code with the same field names and types?
If "yes" then why do I have {"I":0,"lst":[{}]} as the result in test.txt?