First of all, are you using JSONBinder (for parameters to monorail) or
JSONReturnBinder (values being return from Monorail to the browser).
My experience (with complex objects) has only been JSONReturnBinder
although underneath both use json.net so they should be equal adept
going either way.
Here's a sample, directly from my current project:
public class jqGridPacket<T>
{
public jqGridPacket()
{
this.page = 0;
this.records = 0;
this.rows = new T[0];
this.total = 0;
}
public jqGridPacket(IEnumerable<T> coll)
{
if (coll != null)
{
this.rows = coll as T[];
if (this.rows == null)
{
this.rows = coll.ToArray();
}
this.total = 1;
this.page = 1;
this.records = this.rows.Length;
}
}
public int total { get; set; }
public int page { get; set; }
public int records { get; set; }
public T[] rows { get; set; }
}
[return:JSONReturnBinder]
public jqGridPacket<ProductionList> ProductionsJson(int TroupeID, string Season)
{
DateTime seasonStart = DateTime.ParseExact(Season, "yyyy-M-d",
CultureInfo.CurrentCulture);
var productions = from pr in db.Productions
where pr.TroupeID == TroupeID
&& pr.FirstPerformance >= seasonStart
&& pr.FirstPerformance <
seasonStart.AddYears(1)
select new ProductionList
{
ProductionId =
pr.ProductionID.ToString(),
PlayId =
pr.PlayID.ToString(),
Title = pr.Play.Title,
name = pr.Venue.Name,
VenueId =
pr.VenueID.Value.ToString(),
FirstDate =
pr.FirstPerformance,
LastDate =
pr.LastPerformance
};
jqGridPacket<ProductionList> packet = new
jqGridPacket<ProductionList>(productions);
return packet;
}
On Thu, Sep 17, 2009 at 12:51 PM, Cesar Sanz <[email protected]> wrote:
>
> Well, following some examples in php, I am no able to achieve the same
> result with JSONBinder
>
> for instance:
>
> {
> name: 'somename',
> elems:{
> elem1,
> elem2,
> elem3:{
>
> }
> }
> }
>
> This kind of stuffs..
>
> Can you share some example of complex json with monorail? I will appreciate
> it very much.
>
> thanks
>
> ----- Original Message -----
> From: "James Curran" <[email protected]>
> To: <[email protected]>
> Sent: Thursday, September 17, 2009 10:54 AM
> Subject: Re: Monorail + JSon
>
>
>>
>> I've had no problem using JSONBinder to create complex JSON structures
>> (like the structure needed to fill jqGird). What trouble are you
>> having?
>>
>>
>> On Thu, Sep 17, 2009 at 12:41 PM, [email protected]
>> <[email protected]> wrote:
>>>
>>> Hello,
>>>
>>> I want to use extjs in a project, but, ExtJs uses json a lot, I've
>>> seen examples using the JSONBinder but
>>> the json structures used by Extjs are a lot more complex..
>>>
>>> Do you know any form to construct json responses from MonoRail?
>>>
>>>
>>
>>
>>
>> --
>> Truth,
>> James
>>
>> >
>
>
> >
>
--
Truth,
James
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Castle Project Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---