0

I want to parse following JSON

Object { CategoryId: 6, CategoryName: "Blood Blank", CategoryImage: null, CategoryDesc: null }
Object { CategoryId: 10, CategoryName: "Computer Accessories",     CategoryImage: null, CategoryDesc: null } 
Object { CategoryId: 3, CategoryName: "Groceries", CategoryImage: null, CategoryDesc: null }
Object { CategoryId: 2, CategoryName: "Hospitals", CategoryImage: null, CategoryDesc: null } 
Object { CategoryId: 1, CategoryName: "Hotels", CategoryImage: null, CategoryDesc: null }
Object { CategoryId: 5, CategoryName: "Labs", CategoryImage: null, CategoryDesc: null } 
Object { CategoryId: 4, CategoryName: "Medicals", CategoryImage: null, CategoryDesc: null } 
Object { CategoryId: 8, CategoryName: "Staffing Services", CategoryImage: null, CategoryDesc: null } 
Object { CategoryId: 7, CategoryName: "Sweet and Bakeries", CategoryImage: null, CategoryDesc: null }
Object { CategoryId: 9, CategoryName: "Tours and Travels", CategoryImage: null, CategoryDesc: null } 

And I have written following code to parse the JSON , but it is not working

$.ajax({
        url: "/api/Main/GetCategories",
        type: "Get",
        contentType: "application/json",

        success: function (payload) {
            var htmlstring = "<table border=1>";
            htmlstring += "<tr><th>Category Id<th>Category Name<th> Category Image<th> Category Desc";
            // htmlstring += "<th>Likes<th>DisLikes</tr>";
            $.each(payload, function () {
                htmlstring += "<tr>";
                $.each(this, function (k, v) {
                    htmlstring += "<td>" + JSON.parse(JSON.stringify(v));
                    console.log(JSON.parse(JSON.stringify(v)));
                });

            });
            htmlstring += "</table>";
            $("#categorymaster").html(htmlstring);
        },
        error: function (xmlhttp, errstat, errobj) {

            console.log(errobj);
        }
    });

Please help

Hardik Pithva
  • 1,729
  • 1
  • 15
  • 31
Parag Pathari
  • 281
  • 2
  • 5
  • 19
  • Take a look here: [Difference between JSON.stringify and JSON.parse](http://stackoverflow.com/questions/17785592/difference-between-json-stringify-and-json-parse) – R Pelzer Jun 07 '16 at 14:22
  • https://jsfiddle.net/8gsLnj5s/ – brk Jun 07 '16 at 14:41

0 Answers0