{
"javascript": {
"st": 1,
"st2": 2
},
"res": {
"par1": {
"par2": 212
},
"js": 2123
}
}
var str = "javascript.st =1 \
javascript.st1 = 2 \
res.par1.par2 =212 \
res.js =2123";
function parser(str) {
var rgxp = /([\S]*)\s?=\s?(\d*)/g,
result = {},
substr, keys, parents, i;
while (substr = rgxp.exec(str)) {
substr = substr[0].split("=")
keys = substr[0].trim().split(".")
parent = result
for (i = 0, ln = keys.length; i < ln; i++) {
parent[keys[i]] = parent[keys[i]] || {}
i == (ln - 1) ? (parent[keys[i]] = substr[1].trim()) : (parent = parent[keys[i]])
}
}
return result
}
JSON.stringify(parser(str))
// {"javascript":{"st":"1","st1":"2"},"res":{"par1":{"par2":"212"},"js":"2123"}}
$.ajax({
url : '****',
type : "GET",
dataType : "jsonp",
success : function(msg){
var videoparam = [msg.response['url240'],msg.response['url360'],msg.response['url480'],msg.response['url720']];
callOtherFunction(videoparam);
}
});
function callOtherFunction(videoparam) {
/* здесь работаем с массивом */
}
{
"new":"asdsa",
"list":
[
{
"name":"first",
"rating":"50%",
"story":"Once upon a time"
},
{
"name":"second",
"rating":"65%",
"story":"New chapter"
}
]
}
$.getJSON('data.json', function(data){
console.log(data);
});
/*
data - полученный ответ от сервера
*/
var result = [];
for (var i = 0; i < data.length; i++) {
var obj = {};
obj[data[i].name] = data[i].value;
result.push(obj);
}
console.log(result);
// результат
/* [{"assigment":"1"},{"subject":""},{"title":""},{"description":""},{"`pages":""},{"sources`":""},{"id_writer":""},{"discount_code`":""},{"email":""}] */