Est-il possible d'obtenir la liste des attributs d'une carte JSON particulière avec une expression JSONPath? Par exemple:Obtention d'une liste d'attributs dans un JSON
{"foo": 1, "bar": 2}
=>["foo","bar"]
Est-il possible d'obtenir la liste des attributs d'une carte JSON particulière avec une expression JSONPath? Par exemple:Obtention d'une liste d'attributs dans un JSON
{"foo": 1, "bar": 2}
=>["foo","bar"]
boucle à travers chaque objet JSON obtenir toutes les clés et pousser ensuite dans un tableau. Vous pouvez essayer ceci:
var data=[{"foo": 1, "bar": 2},{"foo1": 1, "bar1": 2}];
var array=[];
$.each(data, function(key, value){
var item;
item=Object.keys(value);
array.push(item);
});
console.log(array);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Vous pouvez utiliser le code suivant:
Object.getOwnPropertyNames({"foo": 1, "bar": 2})
Voici un link pour plus d'informations.
Voici un [link] (http://stackoverflow.com/questions/208016/how-to-list-the-properties-of-a-javascript-object) qui pourrait vous aider. –