I'm working on asp.net mvc 4 application which uses Facebook C# SDK (6.0.10.0) and Newtonsoft.Json (4.5.0.0).
Request with FacebookClient returns expando object:
[Authorize]
public ActionResult GetFbData(string path = "me"){
var expando = this.fb.Get(path);
return Json(expando);
}
Returned Json looks like:
[{"Key":"id","Value":"100000xxxxxxxx"},{"Key":"name","Value":"John Doe"} ... ]
I want to return it in format {id:100000xxxxxxx, name:"John Doe", ... }
so I added this to the code which creates my fb client:
fb.SetJsonSerializers(JsonConvert.SerializeObject,
JsonConvert.DeserializeObject);
Same code from above now returns:
[[[]],[[]],[[]],[[]],[[]],[[]],[[[[]],[[]]]],[[[[]],[[]]]],[[]],[[]],[[[[[[[]],[[]]...]
I can get desired result with:
return Content(JsonConvert.SerializeObject(Expando));
This returns proper Json, but Content-Type is text/html; charset=utf-8
, and I'm wondering how I can return the desired format as JsonResult without manually setting response headers etc, I just want to change default serialization behavior without re-implementing serializer etc.
There must be something simple that is done with single line of code to change this behavior, and I'm hoping that someone already found it.