1

To parse multilevel json and to get all the datas. With the below code i can able to get only one Long description from json file.How to show all the long description in the below json file. Please help on this.

<input type="button" value="Get and parse JSON" class="button" />
    <br />
    <span id="results"></span>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

    <script>

        $(document).ready(function() { 
            $('.button').click(function(){        
                $.ajax({
                    url: "http://devcda.bryant.com/bryant/en/us/CommonSearchHandler.ashx?type=17&blogcategories=",                 
                    dataType: "text",                   
                    success: function(data) {                        
                         var json = $.parseJSON(data);


                            $("#results").html('<a href="' + json.CurrentPage + '">' + json.ResultPayload[0].LongDescription + "</a>");

                    }
                });
            });
        });
    </script>

Json file:

{
        "CurrentPage": 0,
        "Facets": null,
        "RecordCount": 1,
        "ResultPayload": [
            {
                "Name": null,
                "URI": "tcm:688-98798",
                "BlogCategories": [
                    "Air Quality"
                ],
                "CreationDate": "January 01, 0001",
                "DisplayTitle": null,
                "LongDescription": "Test1",
                "PageURL": ""
            }
            {
                "Name":null,
                "URI":"tcm:688-98798",
                "BlogCategories":[
                "Air Quality"
                ],
                "CreationDate":"January 01, 0001",
                "DisplayTitle":null,
                "LongDescription":"Test2",
                "PageURL":""
            }
        ],
        "suggestions": null }

1 Answer 1

2

You can iterate over the json.ResultPayload using a for loop

$("#results").empty();
for(var i in  json.ResultPayload){
   $("#results").append('<a href="' + json.CurrentPage + '">' 
        + json.ResultPayload[i].LongDescription + "</a>");
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.