Skip to main content
Relanzada por el usuario Comunidad
Formato Código
Origen Enlace
Juan Pinzón
  • 9.3k
  • 20
  • 54
  • 84

{ "categories": [ { "categori_id": 1, "name": "drinks" }, { "categori_id": 2, "name": "lunch" }, { "categori_id": 3, "name": "food" }, { "categori_id": 4, "name": "sea" } ], "products": [ { "id": 1, "name": "Lorem", "price": "60.000", "available": true, "best_seller": true, "categories": [ 1, 4 ], "img": "", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu." }, { "id": 2, "name": "ipsum", "price": "20.000", "available": false, "best_seller": false, "categories": [ 4 ], "img": "", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu." }, { "id": 3, "name": "dolor", "price": "10.000", "available": true, "best_seller": true, "categories": [ 4 ], "img": "", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu." }, { "id": 4, "name": "sit", "price": "35.000", "available": false, "best_seller": false, "categories": [ 1, 2 ], "img": "", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu." }, { "id": 5, "name": "amet", "price": "12.000", "available": true, "best_seller": true, "categories": [ 1, 4 ], "img": "http://lorempixel.com/200/100/food/", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu." }, { "id": 6, "name": "consectetur", "price": "120.000", "available": true, "best_seller": false, "categories": [ 1, 4 ], "img": "", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu." }, { "id": 7, "name": "adipiscing", "price": "50.000", "available": false, "best_seller": false, "categories": [ 1, 3 ], "img": "", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu." }, { "id": 8, "name": "elit", "price": "2000", "available": true, "best_seller": false, "categories": [ 1, 3 ], "img": "", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu." }, { "id": 9, "name": "Maecenas", "price": "150.000", "available": true, "best_seller": true, "categories": [ 2, 4 ], "img": "", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu." }, { "id": 10, "name": "eu", "price": "200.000", "available": false, "best_seller": true, "categories": [ 2, 3 ], "img": "", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu." } ] }

{
  "categories": [
    {
      "categori_id": 1,
      "name": "drinks"
    },
    {
      "categori_id": 2,
      "name": "lunch"
    },
    {
      "categori_id": 3,
      "name": "food"
    },
    {
      "categori_id": 4,
      "name": "sea"
    }
  ],
  "products": [
    {
      "id": 1,
      "name": "Lorem",
      "price": "60.000",
      "available": true,
      "best_seller": true,
      "categories": [
        1,
        4
      ],
      "img": "",
      "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu."
    },
    {
      "id": 2,
      "name": "ipsum",
      "price": "20.000",
      "available": false,
      "best_seller": false,
      "categories": [
        4
      ],
      "img": "",
      "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu."
    },
    {
      "id": 3,
      "name": "dolor",
      "price": "10.000",
      "available": true,
      "best_seller": true,
      "categories": [
        4
      ],
      "img": "",
      "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu."
    },
    {
      "id": 4,
      "name": "sit",
      "price": "35.000",
      "available": false,
      "best_seller": false,
      "categories": [
        1,
        2
      ],
      "img": "",
      "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu."
    },
    {
      "id": 5,
      "name": "amet",
      "price": "12.000",
      "available": true,
      "best_seller": true,
      "categories": [
        1,
        4
      ],
      "img": "http://lorempixel.com/200/100/food/",
      "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu."
    },
    {
      "id": 6,
      "name": "consectetur",
      "price": "120.000",
      "available": true,
      "best_seller": false,
      "categories": [
        1,
        4
      ],
      "img": "",
      "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu."
    },
    {
      "id": 7,
      "name": "adipiscing",
      "price": "50.000",
      "available": false,
      "best_seller": false,
      "categories": [
        1,
        3
      ],
      "img": "",
      "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu."
    },
    {
      "id": 8,
      "name": "elit",
      "price": "2000",
      "available": true,
      "best_seller": false,
      "categories": [
        1,
        3
      ],
      "img": "",
      "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu."
    },
    {
      "id": 9,
      "name": "Maecenas",
      "price": "150.000",
      "available": true,
      "best_seller": true,
      "categories": [
        2,
        4
      ],
      "img": "",
      "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu."
    },
    {
      "id": 10,
      "name": "eu",
      "price": "200.000",
      "available": false,
      "best_seller": true,
      "categories": [
        2,
        3
      ],
      "img": "",
      "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu."
    }
  ]
}

/*Código JavaScript:/

$(document).ready(function(){

$.ajax({ url: "category.json", // path to file dataType: 'json', // type of file (text, json, xml, etc) success: function(data) { /$.each(data, function(i, item) { console.log(item);

$(document).ready(function(){

  $.ajax({
    url: "category.json", // path to file
    dataType: 'json', // type of file (text, json, xml, etc)
     success: function(data) {
     /$.each(data, function(i, item) {
          console.log(item);

      });/
    
     jQuery.each( data, function( i, val ) {
  $( "body" ).append( document.createTextNode( " - " + val ) );
});
    },
    error: function() {
      alert("error");
    }
  });     

});

$( "body" ).append( document.createTextNode( " - " + val ) ); }); }, error: function() { alert("error"); } });

});

{ "categories": [ { "categori_id": 1, "name": "drinks" }, { "categori_id": 2, "name": "lunch" }, { "categori_id": 3, "name": "food" }, { "categori_id": 4, "name": "sea" } ], "products": [ { "id": 1, "name": "Lorem", "price": "60.000", "available": true, "best_seller": true, "categories": [ 1, 4 ], "img": "", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu." }, { "id": 2, "name": "ipsum", "price": "20.000", "available": false, "best_seller": false, "categories": [ 4 ], "img": "", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu." }, { "id": 3, "name": "dolor", "price": "10.000", "available": true, "best_seller": true, "categories": [ 4 ], "img": "", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu." }, { "id": 4, "name": "sit", "price": "35.000", "available": false, "best_seller": false, "categories": [ 1, 2 ], "img": "", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu." }, { "id": 5, "name": "amet", "price": "12.000", "available": true, "best_seller": true, "categories": [ 1, 4 ], "img": "http://lorempixel.com/200/100/food/", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu." }, { "id": 6, "name": "consectetur", "price": "120.000", "available": true, "best_seller": false, "categories": [ 1, 4 ], "img": "", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu." }, { "id": 7, "name": "adipiscing", "price": "50.000", "available": false, "best_seller": false, "categories": [ 1, 3 ], "img": "", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu." }, { "id": 8, "name": "elit", "price": "2000", "available": true, "best_seller": false, "categories": [ 1, 3 ], "img": "", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu." }, { "id": 9, "name": "Maecenas", "price": "150.000", "available": true, "best_seller": true, "categories": [ 2, 4 ], "img": "", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu." }, { "id": 10, "name": "eu", "price": "200.000", "available": false, "best_seller": true, "categories": [ 2, 3 ], "img": "", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu." } ] }

/*Código JavaScript:/

$(document).ready(function(){

$.ajax({ url: "category.json", // path to file dataType: 'json', // type of file (text, json, xml, etc) success: function(data) { /$.each(data, function(i, item) { console.log(item);

  });/

 jQuery.each( data, function( i, val ) {

$( "body" ).append( document.createTextNode( " - " + val ) ); }); }, error: function() { alert("error"); } });

});

{
  "categories": [
    {
      "categori_id": 1,
      "name": "drinks"
    },
    {
      "categori_id": 2,
      "name": "lunch"
    },
    {
      "categori_id": 3,
      "name": "food"
    },
    {
      "categori_id": 4,
      "name": "sea"
    }
  ],
  "products": [
    {
      "id": 1,
      "name": "Lorem",
      "price": "60.000",
      "available": true,
      "best_seller": true,
      "categories": [
        1,
        4
      ],
      "img": "",
      "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu."
    },
    {
      "id": 2,
      "name": "ipsum",
      "price": "20.000",
      "available": false,
      "best_seller": false,
      "categories": [
        4
      ],
      "img": "",
      "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu."
    },
    {
      "id": 3,
      "name": "dolor",
      "price": "10.000",
      "available": true,
      "best_seller": true,
      "categories": [
        4
      ],
      "img": "",
      "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu."
    },
    {
      "id": 4,
      "name": "sit",
      "price": "35.000",
      "available": false,
      "best_seller": false,
      "categories": [
        1,
        2
      ],
      "img": "",
      "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu."
    },
    {
      "id": 5,
      "name": "amet",
      "price": "12.000",
      "available": true,
      "best_seller": true,
      "categories": [
        1,
        4
      ],
      "img": "http://lorempixel.com/200/100/food/",
      "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu."
    },
    {
      "id": 6,
      "name": "consectetur",
      "price": "120.000",
      "available": true,
      "best_seller": false,
      "categories": [
        1,
        4
      ],
      "img": "",
      "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu."
    },
    {
      "id": 7,
      "name": "adipiscing",
      "price": "50.000",
      "available": false,
      "best_seller": false,
      "categories": [
        1,
        3
      ],
      "img": "",
      "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu."
    },
    {
      "id": 8,
      "name": "elit",
      "price": "2000",
      "available": true,
      "best_seller": false,
      "categories": [
        1,
        3
      ],
      "img": "",
      "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu."
    },
    {
      "id": 9,
      "name": "Maecenas",
      "price": "150.000",
      "available": true,
      "best_seller": true,
      "categories": [
        2,
        4
      ],
      "img": "",
      "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu."
    },
    {
      "id": 10,
      "name": "eu",
      "price": "200.000",
      "available": false,
      "best_seller": true,
      "categories": [
        2,
        3
      ],
      "img": "",
      "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu."
    }
  ]
}

Código JavaScript:

$(document).ready(function(){

  $.ajax({
    url: "category.json", // path to file
    dataType: 'json', // type of file (text, json, xml, etc)
     success: function(data) {
     /$.each(data, function(i, item) {
          console.log(item);

      });/
    
     jQuery.each( data, function( i, val ) {
  $( "body" ).append( document.createTextNode( " - " + val ) );
});
    },
    error: function() {
      alert("error");
    }
  });     

});
Origen Enlace

Resultado: [object], [object] al importar un archivo JSON

Tengo un problema para obtener datos de un archivo JSON, cuándo intento obtener los datos de este archivo, obtengo como resultado: [object], [object]

{ "categories": [ { "categori_id": 1, "name": "drinks" }, { "categori_id": 2, "name": "lunch" }, { "categori_id": 3, "name": "food" }, { "categori_id": 4, "name": "sea" } ], "products": [ { "id": 1, "name": "Lorem", "price": "60.000", "available": true, "best_seller": true, "categories": [ 1, 4 ], "img": "", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu." }, { "id": 2, "name": "ipsum", "price": "20.000", "available": false, "best_seller": false, "categories": [ 4 ], "img": "", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu." }, { "id": 3, "name": "dolor", "price": "10.000", "available": true, "best_seller": true, "categories": [ 4 ], "img": "", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu." }, { "id": 4, "name": "sit", "price": "35.000", "available": false, "best_seller": false, "categories": [ 1, 2 ], "img": "", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu." }, { "id": 5, "name": "amet", "price": "12.000", "available": true, "best_seller": true, "categories": [ 1, 4 ], "img": "http://lorempixel.com/200/100/food/", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu." }, { "id": 6, "name": "consectetur", "price": "120.000", "available": true, "best_seller": false, "categories": [ 1, 4 ], "img": "", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu." }, { "id": 7, "name": "adipiscing", "price": "50.000", "available": false, "best_seller": false, "categories": [ 1, 3 ], "img": "", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu." }, { "id": 8, "name": "elit", "price": "2000", "available": true, "best_seller": false, "categories": [ 1, 3 ], "img": "", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu." }, { "id": 9, "name": "Maecenas", "price": "150.000", "available": true, "best_seller": true, "categories": [ 2, 4 ], "img": "", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu." }, { "id": 10, "name": "eu", "price": "200.000", "available": false, "best_seller": true, "categories": [ 2, 3 ], "img": "", "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu." } ] }

/*Código JavaScript:/

$(document).ready(function(){

$.ajax({ url: "category.json", // path to file dataType: 'json', // type of file (text, json, xml, etc) success: function(data) { /$.each(data, function(i, item) { console.log(item);

  });/

 jQuery.each( data, function( i, val ) {

$( "body" ).append( document.createTextNode( " - " + val ) ); }); }, error: function() { alert("error"); } });

});

Por favor me gustaría saber que está pasando.