Answer the question
In order to leave comments, you need to log in
How to universally parse json into blocks using jquery?
Good afternoon.
There is a page that is formed by the view:
<span data-jsonItem="key1" data-jsonValue="val">error</span>
<span data-jsonItem="key1" data-jsonValue="val2">error</span>
<span data-jsonItem="key2" data-jsonValue="val">error</span>
<span data-jsonItem="key2" data-jsonValue="val2">error</span>
function jsonUPDATE() {
var URL = "/json.json";
$.getJSON(URL, function(data){
$.each(data, function (item, value) {
var jsonItem = "key1";
if (item == jsonItem) {
$.each(value, function (i, object) {
$.each(object, function (subI, subObject) {
$("[data-jsonValue='"+subI+"']").html(subObject);
});
});
}
});
});
}
{
"key1": [
{
"val": 0,
"val2": 0,
"val3": 0,
}
],
"key2": [
{
"val": 0,
"val2": 0,
"val3": 0,
}
]
}
Answer the question
In order to leave comments, you need to log in
$(document).ready(function() {
var result = data['items'];
var oE = $(""); // ID блока
if (oE.length == 0) oE = null;
$.each(data['items'], function(index, value) {
oE.append($(' ')); // Суда упакуй то что хочешь вывести в html
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question