Question

I need to return json with this structure :

{"asks": [[PRICE, AMOUNT], ...],
 "bids": [[PRICE, AMOUNT], ...]}

PRICE is decimal. AMOUNT is decimal

example

{"asks":[[7.449,1],[7.4499,6.711]],
 "bids":[[7.40001,5],[7.3325,27.449]]}

I have a controller with action

public ActionResult GetTrades() 
{
  ///how should I construct the object ? 
  return Json(data, JsonRequestBehavior.AllowGet);
}

I've tried to return this object :

public class OrderBook
{
    public List<KeyValuePair<decimal, decimal>> asks { get; set; }
    public List<KeyValuePair<decimal, decimal>> bids { get; set; }
}

but I get response like this:

{"asks":[{"Key":145.00000,"Value":152.38820689}],
 "bids":[{"Key":145.00000,"Value":3.48965517}]}

any Idea?

Was it helpful?

Solution

Replace KeyValuePair with either a List<decimal> or decimal[2].

OTHER TIPS

As you're using the same data type for key and value then perhaps List is a possibility, where each decimal array would be of length 2 in your case.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top