Why does the following code return "[ ]" when it should return "{"id":1999, "title":"hithere"}
JavaScriptSerializer serializer = new JavaScriptSerializer();
StringBuilder sbJsonResults = new StringBuilder();
var result = serializer.Serialize(new dg(1999, "hithere"));
context.Response.Clear();
context.Response.ContentType = "application/json; charset=utf-8";
context.Response.Cache.SetExpires(DateTime.MinValue);
context.Response.Write(result);
P.S. the dg class looks like this:
public class dg : ScheduleObserver, ILibrary, IEnumerable {
public int id;
public string title;
private List<d> dList;
...many getters and setters and some logic functions...
}
public abstract class ScheduleObserver{
public abstract void update();
}
public interface ILibrary {
List<PD> getPDs();
void setPDs(List<PD> newPDs);
int getCurrentIndex();
void addPD(PD pD);
PD getPD(int index);
}
Many thanks.
THANKS - ANSWERED SUCCESSFULLY - it was the IEnumerable that was the source of my woes. To solve it, dg no longer extends IEnumerable and all foreach (dg...) loops have been converted back into for(int i = 0...) loops.
THANKS VERY, VERY MUCH! JAMES got why its empty, Parv got why had square brackets. Would mark both as answer but can only mark one.
dg
=[serializable]
? – EyreScheduleObserver
but from what I can see you don't have any public setters/getters. – Phytoplankton