cela peut être une question de syntaxe plus que tout, mais j'importer JSON en feuilles de google avec le script suivant:Importation valeur du tableau JSON à Google Sheets
function IMPORTJSON(url,xpath){
try{
var res = UrlFetchApp.fetch(url);
var content = res.getContentText();
var json = JSON.parse(content);
var patharray = xpath.split("/");
for(var i=0;i<patharray.length;i++){
json = json[patharray[i]];
}
if(typeof(json) === "undefined"){
return "Not available";
} else if(typeof(json) === "object"){
var tempArr = [];
for(var obj in json){
tempArr.push([obj,json[obj]]);
}
return tempArr;
} else if(typeof(json) !== "object") {
return json;
}
}
catch(err){
return "Error";
}
}
Je suis en mesure d'obtenir des valeurs bien, La syntaxe pour quelque chose de simple comme nom de ceci: "productinfo": { "name":, "url": }
est juste =IMPORTJSON(urlgoeshere,"productinfo/name")
. Mais je ne peux pas comprendre comment obtenir une valeur dans un tableau. Disons par exemple que je tentais d'obtenir l'URL de l'image avant de celle-ci:
"images": [ {
"front": "http://front.jpg",
"back": "http://back.jpg",
"side": "http://side.jpg"
} ]
J'ai essayé un certain nombre de choses comme "images/front"
, "images[0]/front"
mais ai pas de chance. Des idées?
Je l'ai compris, c'était purement syntaxique. ex: 'images/0/front' – screampuff