#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    853
    Rep Power
    12

    JSON to hml and data formatting


    I have a page where I make a ajax request and get the data in json format
    I need to render this json response as tables in html
    Is there any common functions/libraries I can use so that I dont have to loop through this json to render in html?


    Also, Is there any data formatting libraries too which can show phone number input as 1111222233 as
    111-1222-233
    or dates coming from backend - 02/13/2013 as
    Feb-13-2013 etc
    Contact info:
    Primary email: advanced.programmer@gmail.com
    MSN/email: superprg@hotmail.com
    AIM: superprg
  2. #2
  3. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,187
    Rep Power
    184
    Do a Google search; you will get many results for converting "JSON to HTML".

    Code:
    <script>
    
    var phone_number = 1111222233;
    
    var backend_date = "02/13/2013";
    
    var months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
    
    function convert_phone()
    {
    phone_number = phone_number.toString();
    var area_code = phone_number.substring(0,3);
    var prefix = phone_number.substring(3,6);
    var suffix = phone_number.substring(6,10);
    var convertedNumber = area_code + "-" + prefix + "-" + suffix;
    alert(convertedNumber);
    }
    
    function convert_date()
    {
    var divider = backend_date.split("/");
    var month = parseFloat(divider[0]) - 1;
    month = months[month];
    var day = divider[1];
    var year = divider[2];
    var fully_converted_date = month + "-" + day + "-" + year;
    alert(fully_converted_date);
    }
    
    window.onload = function() {
    convert_phone();
    convert_date();
    }
    
    </script>

IMN logo majestic logo threadwatch logo seochat tools logo