You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a custom object - and I want to return an array of the object as a
JSON string:
public class custom_obj
{
private int _age;
public int age
{
get { return this._age; }
set { this._age = value; }
}
}
custom_obj co;
List<custom_obj> co_list = new List<custom_obj>();
for (int i = 0; i < 5; ++i)
{
co = new custom_obj();
co.age = i;
co_list.Add(co);
}
JSONReflector json = new JSONReflector(co_list);
Console.WriteLine(json.ToString());
Here's what I would expect:
[ {"age":0},{"age":1},{"age":2},{"age":3},{"age":4}]
Instead, I get an Exception:
"System.Reflection.TargetParameterCountException: Parameter count mismatch."
[TargetParameterCountException: Parameter count mismatch.]
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture,
Boolean skipVisibilityChecks) +2754022
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29
System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] index, CultureInfo culture) +55
System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[]
index) +18
JSONSharp.JSONReflector..ctor(Object objValue) +167
If I create the JSONReflector on a *single instance* of custom_obj - it
works just fine. It just can't seem to handle an array of custom_obj objects.
Is this a limitation of JSONSharp or am I doing it wrong?
Original issue reported on code.google.com by jtre...@gmail.com on 6 Oct 2009 at 4:43
The text was updated successfully, but these errors were encountered:
You neeed a wrapper for your list, then you can call it like this:
Wrapper wrapper = new Wrapper();
wrapper.CustomObjects = co_list.ToArray();
JSONReflector json = new JSONReflector(wrapper);
Console.WriteLine(json.ToString());
*****
public class Wrapper
{
private custom_obj[] _customObjects;
public custom_obj[] CustomObjects
{
get
{
return _customObjects;
}
set
{
_customObjects = value;
}
}
}
Original comment by len...@gmail.com on 5 Nov 2009 at 2:11
Original issue reported on code.google.com by
jtre...@gmail.com
on 6 Oct 2009 at 4:43The text was updated successfully, but these errors were encountered: