1

Hi Below is code of second level json array parsing. First level json output i can able to fetch. second level i cant. i.e under CategoryImage i have two attributes which i couldn't able to fetch can anyone help on this.Thanks

<script>        
        $(document).ready(function() {
          var cat="";
           categories(cat);
            $('ul li').click(function(){
                var cat = $(this).text();               
                categories(cat);               
            });
        });
        function categories(cat){                
             $.ajax({
                    url: "http://devcda.bryant.com/bryant/en/us/CommonSearchHandler.ashx?type=17&blogcategories="+cat,                                  dataType: "text",                   
                    success: function(data) {                        
                        var json = $.parseJSON(data);
                        var e="";
                        $(".blog_desc").remove();
                       for(var i in  json.ResultPayload){


                           e+="<div class='blog_desc'>";
                           e+="<div class='tmpstr_hdr_cntnt container'>";
                           e+=" <div class='col-lg-9 col-md-10 col-sm-10 col-xs-12'>"  ;
                           e+="<h3>"+json.ResultPayload[i].DisplayTitle+"</h3>";
                           e+="<p><span class='date_blg'>"+json.ResultPayload[i].CreationDate+"</span>Categories: <span class='cat_blg'>"+json.ResultPayload[i].BlogCategories+"</span></p>";                          
                           e+="<div class='col-lg-3 col-md-3 col-sm-3 col-xs-12'><img src="+json.ResultPayload[i].CategoryImage[i].Path+" class='img-responsive'>  </div>";

                           e+="<div class='col-lg-9 col-md-9 col-sm-9 col-xs-12'><p>"+json.ResultPayload[i].LongDescription+"</p>";
                           e+="<p class='read_more'><a href="+json.ResultPayload[i].PageURL+">READ MORE</a></p>";
                           e+="</div>";                        
                           e+="</div>"; 
                           e+="</div>";
                           e+="</div>";
                          } 


                        $("input").after(e);

                    }
                });


        }

    </script>

Json file

{  
   "CurrentPage":0,
   "Facets":null,
   "RecordCount":4,
   "ResultPayload":[  
      {  
         "Name":null,
         "URI":"tcm:688-98862",
         "BlogCategories":[  
            "Efficiency"
         ],
         "CreationDate":"September 01, 2015",
         "DisplayTitle":"How often should you change your furnace filter?",
         "LongDescription":"How often should you change your furnace filter? How often should you change your furnace filter?How often should you change your furnace filter?How often should you change your furnace filter?How often should you change your furnace filter?How often should you change your furnace filter?",
         "PageURL":""
      },
      {  
         "Name":null,
         "URI":"tcm:688-98863",
         "BlogCategories":[  
            "Air Quality"
         ],
         "CreationDate":"September 01, 2015",
         "DisplayTitle":"Test",
         "LongDescription":"Test",
         "PageURL":""
      },
      {  
         "Name":null,
         "URI":"tcm:688-98798",
         "BlogCategories":[  
            "Air Quality"
         ],
         "CreationDate":"September 01, 2015",
         "DisplayTitle":"Test",
         "LongDescription":"Test",
         "PageURL":"\/bryant\/en\/us\/about-bryant\/blog\/blog-details\/Test%20Air%20quality.aspx"
      },
      {  
         "Name":null,
         "URI":"tcm:688-96383",
         "BlogCategories":[  
            "Efficiency"
         ],
         "CategoryImage":{  
            "AltText":"Blog_Detail_12345",
            "Path":"\/\/files.dev.bryant.com\/Bryant\/en\/us\/contentimages\/Blog_Detail_12345.png"
         },
         "CreationDate":"September 01, 2015",
         "DisplayTitle":"How often should you change your furnace filter?",
         "LongDescription":"How often should you change your furnace filter? How often should you change your furnace filter?How often should you change your furnace filter?How often should you change your furnace filter?How often should you change your furnace filter?How often should you change your furnace filter?",
         "PageURL":"\/bryant\/en\/us\/about-bryant\/blog\/blog-details\/How%20often%20should%20you%20change%20your%20furnace%20filter.aspx"
      }
   ],
   "suggestions":null
}
1
  • can you provide js fiddle for the same? Commented Sep 14, 2015 at 10:29

1 Answer 1

2

CategoryImage is not an array so ResultPayload[i].CategoryImage.Path should work

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks calinaadi..I tired someother way and fixed

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.