Skip to main content
Removed non-pertinent nontechnical chat, leaving the technical content of the question.
Source Link
Ram
  • 3.1k
  • 10
  • 43
  • 57

I am trying to parse a jsonJSON file that contains product categories, then the products within those categories, and display them in a divdiv.

My problem: while I can get the categories, I don't know how to ask for the products (and have them appear under the categories).

Here is myMy script:

<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>

<script>
  $.getJSON('https://example.com/GetProductList/', function(data) {
        var output="<ul>";
        for (var i in data.Categories) {
            output+="<li>" + data.Categories[i].Category + "</li>";
        }
        output+="</ul>";
        document.getElementById("testdiv").innerHTML=output;
  });
</script>

And here is the JsonThe JSON I'm trying to parse:

{
  "List": "GetProductList",
  "Categories": [{
    "Category": "Featured",
    "Products": [{
      "product_id": "2",
      "short_description": "short desc 2",
      "cost": "20"
    }]
  }, {
    "Category": "Automotive",
    "Products": ""
  }, {
    "Category": "Electronics",
    "Products": ""
  }, {
    "Category": "Sporting Goods",
    "Products": [{
      "product_id": "2",
      "short_description": "short desc 2",
      "cost": "20"
    }, {
      "product_id": "3",
      "short_description": "short desc 3",
      "cost": "30"
    }]
  }, {
    "Category": "Housewares",
    "Products": [{
      "product_id": "1",
      "short_description": "short desc",
      "cost": "10"
    }]
  }, ]
}

I'm able to get the categories and show them in the div (testdivtestdiv), but how do I get the Product info as well?

I am trying to parse a json file that contains product categories, then the products within those categories, and display them in a div.

My problem: while I can get the categories, I don't know how to ask for the products (and have them appear under the categories).

Here is my script:

<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>

<script>
  $.getJSON('https://example.com/GetProductList/', function(data) {
        var output="<ul>";
        for (var i in data.Categories) {
            output+="<li>" + data.Categories[i].Category + "</li>";
        }
        output+="</ul>";
        document.getElementById("testdiv").innerHTML=output;
  });
</script>

And here is the Json I'm trying to parse:

{
  "List": "GetProductList",
  "Categories": [{
    "Category": "Featured",
    "Products": [{
      "product_id": "2",
      "short_description": "short desc 2",
      "cost": "20"
    }]
  }, {
    "Category": "Automotive",
    "Products": ""
  }, {
    "Category": "Electronics",
    "Products": ""
  }, {
    "Category": "Sporting Goods",
    "Products": [{
      "product_id": "2",
      "short_description": "short desc 2",
      "cost": "20"
    }, {
      "product_id": "3",
      "short_description": "short desc 3",
      "cost": "30"
    }]
  }, {
    "Category": "Housewares",
    "Products": [{
      "product_id": "1",
      "short_description": "short desc",
      "cost": "10"
    }]
  }, ]
}

I'm able to get the categories and show them in the div (testdiv), but how do I get the Product info as well?

I am trying to parse a JSON file that contains product categories, then the products within those categories, and display them in a div.

My problem: while I can get the categories, I don't know how to ask for the products (and have them appear under the categories).

My script:

<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>

<script>
  $.getJSON('https://example.com/GetProductList/', function(data) {
        var output="<ul>";
        for (var i in data.Categories) {
            output+="<li>" + data.Categories[i].Category + "</li>";
        }
        output+="</ul>";
        document.getElementById("testdiv").innerHTML=output;
  });
</script>

The JSON I'm trying to parse:

{
  "List": "GetProductList",
  "Categories": [{
    "Category": "Featured",
    "Products": [{
      "product_id": "2",
      "short_description": "short desc 2",
      "cost": "20"
    }]
  }, {
    "Category": "Automotive",
    "Products": ""
  }, {
    "Category": "Electronics",
    "Products": ""
  }, {
    "Category": "Sporting Goods",
    "Products": [{
      "product_id": "2",
      "short_description": "short desc 2",
      "cost": "20"
    }, {
      "product_id": "3",
      "short_description": "short desc 3",
      "cost": "30"
    }]
  }, {
    "Category": "Housewares",
    "Products": [{
      "product_id": "1",
      "short_description": "short desc",
      "cost": "10"
    }]
  }, ]
}

I'm able to get the categories and show them in the div (testdiv), but how do I get the Product info as well?

Removed non-pertinent nontechnical chat, leaving the technical content of the question.
Source Link

I apologize in advance for this (hopefully) being a really dumb question. I'm a complete newbie to this and am trying to parse a json file that contains product categories, then the products within those categories, and display them in a div.

I've spent hours searching andMy problem: while I can get the categories, I don't know how to ask for the products (and have them appear under the categories). I hope this makes sense.

Anyway hereHere is my script:

<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>

<script>
  $.getJSON('https://example.com/GetProductList/', function(data) {
        var output="<ul>";
        for (var i in data.Categories) {
            output+="<li>" + data.Categories[i].Category + "</li>";
        }
        output+="</ul>";
        document.getElementById("testdiv").innerHTML=output;
  });
</script>

And here is the Json I'm trying to parse:

{
  "List": "GetProductList",
  "Categories": [{
    "Category": "Featured",
    "Products": [{
      "product_id": "2",
      "short_description": "short desc 2",
      "cost": "20"
    }]
  }, {
    "Category": "Automotive",
    "Products": ""
  }, {
    "Category": "Electronics",
    "Products": ""
  }, {
    "Category": "Sporting Goods",
    "Products": [{
      "product_id": "2",
      "short_description": "short desc 2",
      "cost": "20"
    }, {
      "product_id": "3",
      "short_description": "short desc 3",
      "cost": "30"
    }]
  }, {
    "Category": "Housewares",
    "Products": [{
      "product_id": "1",
      "short_description": "short desc",
      "cost": "10"
    }]
  }, ]
}

I'm able to get the categories and show them in the div (testdiv), but how do I get the Product info as well?

Thanks so much.

I apologize in advance for this (hopefully) being a really dumb question. I'm a complete newbie to this and am trying to parse a json file that contains product categories, then the products within those categories and display them in a div.

I've spent hours searching and while I can get the categories, I don't know how to ask for the products (and have them appear under the categories). I hope this makes sense.

Anyway here is my script:

<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>

<script>
  $.getJSON('https://example.com/GetProductList/', function(data) {
        var output="<ul>";
        for (var i in data.Categories) {
            output+="<li>" + data.Categories[i].Category + "</li>";
        }
        output+="</ul>";
        document.getElementById("testdiv").innerHTML=output;
  });
</script>

And here is the Json I'm trying to parse:

{
  "List": "GetProductList",
  "Categories": [{
    "Category": "Featured",
    "Products": [{
      "product_id": "2",
      "short_description": "short desc 2",
      "cost": "20"
    }]
  }, {
    "Category": "Automotive",
    "Products": ""
  }, {
    "Category": "Electronics",
    "Products": ""
  }, {
    "Category": "Sporting Goods",
    "Products": [{
      "product_id": "2",
      "short_description": "short desc 2",
      "cost": "20"
    }, {
      "product_id": "3",
      "short_description": "short desc 3",
      "cost": "30"
    }]
  }, {
    "Category": "Housewares",
    "Products": [{
      "product_id": "1",
      "short_description": "short desc",
      "cost": "10"
    }]
  }, ]
}

I'm able to get the categories and show them in the div (testdiv), but how do I get the Product info as well?

Thanks so much.

I am trying to parse a json file that contains product categories, then the products within those categories, and display them in a div.

My problem: while I can get the categories, I don't know how to ask for the products (and have them appear under the categories).

Here is my script:

<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>

<script>
  $.getJSON('https://example.com/GetProductList/', function(data) {
        var output="<ul>";
        for (var i in data.Categories) {
            output+="<li>" + data.Categories[i].Category + "</li>";
        }
        output+="</ul>";
        document.getElementById("testdiv").innerHTML=output;
  });
</script>

And here is the Json I'm trying to parse:

{
  "List": "GetProductList",
  "Categories": [{
    "Category": "Featured",
    "Products": [{
      "product_id": "2",
      "short_description": "short desc 2",
      "cost": "20"
    }]
  }, {
    "Category": "Automotive",
    "Products": ""
  }, {
    "Category": "Electronics",
    "Products": ""
  }, {
    "Category": "Sporting Goods",
    "Products": [{
      "product_id": "2",
      "short_description": "short desc 2",
      "cost": "20"
    }, {
      "product_id": "3",
      "short_description": "short desc 3",
      "cost": "30"
    }]
  }, {
    "Category": "Housewares",
    "Products": [{
      "product_id": "1",
      "short_description": "short desc",
      "cost": "10"
    }]
  }, ]
}

I'm able to get the categories and show them in the div (testdiv), but how do I get the Product info as well?

added 62 characters in body
Source Link
Dhiraj
  • 33.7k
  • 10
  • 65
  • 78

I apologize in advance for this (hopefully) being a really dumb question. I'm a complete newbie to this and am trying to parse a json file that contains product categories, then the products within those categories and display them in a div.

I've spent hours searching and while I can get the categories, I don't know how to ask for the products (and have them appear under the categories). I hope this makes sense.

Anyway here is my script:

<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>

<script>
  $.getJSON('https://example.com/GetProductList/', function(data) {
        var output="<ul>";
        for (var i in data.Categories) {
            output+="<li>" + data.Categories[i].Category + "</li>";
        }
        output+="</ul>";
        document.getElementById("testdiv").innerHTML=output;
  });
    </script>

And here is the Json I'm trying to parse:

{
  "List": "GetProductList",
  "Categories": [
 {
    "Category": "Featured",
    "Products": [
 {
      "product_id": "2",
      "short_description": "short desc 2",
      "cost": "20"
    }
 ]
  },
  {
    "Category": "Automotive",
    "Products": ""
  },
  {
    "Category": "Electronics",
    "Products": ""
  },
  {
    "Category": "Sporting Goods",
    "Products": [
 {
      "product_id": "2",
      "short_description": "short desc 2",
      "cost": "20"
    },
  {
      "product_id": "3",
      "short_description": "short desc 3",
      "cost": "30"
    }
 ]
  },
  {
    "Category": "Housewares",
    "Products": [
 {
      "product_id": "1",
      "short_description": "short desc",
      "cost": "10"
    }
 ]
  },
  ]
}

I'm able to get the categories and show them in the div (testdiv), but how do I get the Product info as well?

Thanks so much.

I apologize in advance for this (hopefully) being a really dumb question. I'm a complete newbie to this and am trying to parse a json file that contains product categories, then the products within those categories and display them in a div.

I've spent hours searching and while I can get the categories, I don't know how to ask for the products (and have them appear under the categories). I hope this makes sense.

Anyway here is my script:

<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>

<script>
  $.getJSON('https://example.com/GetProductList/', function(data) {
        var output="<ul>";
        for (var i in data.Categories) {
            output+="<li>" + data.Categories[i].Category + "</li>";
        }
        output+="</ul>";
        document.getElementById("testdiv").innerHTML=output;
  });
    </script>

And here is the Json I'm trying to parse:

{
"List": "GetProductList",
"Categories": [
 {
"Category": "Featured",
"Products": [
 {
"product_id": "2",
"short_description": "short desc 2",
"cost": "20"
}
 ]
},
 {
"Category": "Automotive",
"Products": ""
},
 {
"Category": "Electronics",
"Products": ""
},
 {
"Category": "Sporting Goods",
"Products": [
 {
"product_id": "2",
"short_description": "short desc 2",
"cost": "20"
},
 {
"product_id": "3",
"short_description": "short desc 3",
"cost": "30"
}
 ]
},
 {
"Category": "Housewares",
"Products": [
 {
"product_id": "1",
"short_description": "short desc",
"cost": "10"
}
 ]
},
 ]
}

I'm able to get the categories and show them in the div (testdiv), but how do I get the Product info as well?

Thanks so much.

I apologize in advance for this (hopefully) being a really dumb question. I'm a complete newbie to this and am trying to parse a json file that contains product categories, then the products within those categories and display them in a div.

I've spent hours searching and while I can get the categories, I don't know how to ask for the products (and have them appear under the categories). I hope this makes sense.

Anyway here is my script:

<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>

<script>
  $.getJSON('https://example.com/GetProductList/', function(data) {
        var output="<ul>";
        for (var i in data.Categories) {
            output+="<li>" + data.Categories[i].Category + "</li>";
        }
        output+="</ul>";
        document.getElementById("testdiv").innerHTML=output;
  });
</script>

And here is the Json I'm trying to parse:

{
  "List": "GetProductList",
  "Categories": [{
    "Category": "Featured",
    "Products": [{
      "product_id": "2",
      "short_description": "short desc 2",
      "cost": "20"
    }]
  }, {
    "Category": "Automotive",
    "Products": ""
  }, {
    "Category": "Electronics",
    "Products": ""
  }, {
    "Category": "Sporting Goods",
    "Products": [{
      "product_id": "2",
      "short_description": "short desc 2",
      "cost": "20"
    }, {
      "product_id": "3",
      "short_description": "short desc 3",
      "cost": "30"
    }]
  }, {
    "Category": "Housewares",
    "Products": [{
      "product_id": "1",
      "short_description": "short desc",
      "cost": "10"
    }]
  }, ]
}

I'm able to get the categories and show them in the div (testdiv), but how do I get the Product info as well?

Thanks so much.

Source Link
Loading