locked
JSON output RRS feed

  • Question

  • User1519602350 posted

    Hi - Below code is perfectly working fine and output as json format.

        Layout = null;
        var db = Database.Open("dbs");
        var rows = db.Query(@"SELECT postingID, title, shortdescription, SUBSTRING(description, 1, 100) as description FROM Posting " +
                    "LEFT OUTER JOIN Categories ON Posting.category = Categories.categoryID " +
                    "WHERE Categories.categoryID = 1 ORDER BY Posting.postingID DESC");
     
        
                        Response.ContentType = "application/json";
                        Json.Write(rows, Response.Output);
     
        
     
     
                    }

    Result is

    [{"PostingID":426,"title":" "}]
    
    
    

    I would like to add "books" as a group for this json output. Example

    { "books": [{"PostingID":426,"title":" "}]
    }

    Thanks

    Monday, May 13, 2013 9:08 AM

Answers

  • User1557244751 posted

    Try below code

    Json.Write(new {books = rows}, Response.Output);
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 13, 2013 9:15 AM