{"id":4166,"date":"2014-03-30T08:46:29","date_gmt":"2014-03-30T08:46:29","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/returning-empty-json-object-collection-of-common-programming-errors-2\/"},"modified":"2014-03-30T08:46:29","modified_gmt":"2014-03-30T08:46:29","slug":"returning-empty-json-object-collection-of-common-programming-errors-2","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/returning-empty-json-object-collection-of-common-programming-errors-2\/","title":{"rendered":"Returning Empty Json Object-Collection of common programming errors"},"content":{"rendered":"<p>In C# we have properties which (in C# 3+) can be automatically created.<\/p>\n<pre><code>public class A\n{\n    public string Name { get; set; }\n}\n<\/code><\/pre>\n<p>Secondly you will need to return your object wrapped in a new object in order for the JSON to return correctly. You do not need to serialize the object yourself (since you could just return it as an <code>ActionResult<\/code> otherwise).<\/p>\n<pre><code>public JsonResult Hello()\n{\n    A obj = new A();\n    obj.Name = \"Abc\";\n    return Json(new { obj }, JsonRequestBehavior.AllowGet);\n}\n<\/code><\/pre>\n<p>This will create a new Json object <code>{\"obj\":{\"Name\":\"Abc\"}}<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In C# we have properties which (in C# 3+) can be automatically created. public class A { public string Name { get; set; } } Secondly you will need to return your object wrapped in a new object in order for the JSON to return correctly. You do not need to serialize the object yourself [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4166","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4166","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4166"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4166\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}