このようなjson形式で返された各サブオブジェクトに対してローカルにデータを格納したいですか? `key-name sectionType +セクションタイプ、値 - このオブジェクト各jsonサブオブジェクトのループを使用してローカルストレージ内のJsonデータを取得します
私の既存のJSコード:
function syncAllSections_4(){
\t \t user_sections= loggeduser_array.id;
\t \t console.log(user_sections);
var dict_4 = { userId: user_sections };
$.ajax({
url: 'http://funiks.com/adminv7/offline-api/listSections.php',
type: 'POST',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
data: JSON.stringify(dict_4),
})
.done(function(data, textStatus, jqXHR) {
\t if(data.status=="SUCCESS") {
localStorage.setItem("sections",JSON.stringify(data.sections));
//console.log(JSON.parse(localStorage.getItem("sections")));
\t
\t var sections_array = [];
\t sections_array = JSON.parse(localStorage.getItem("sections"));
\t }
}).fail(function(jqXHR, textStatus, errorThrown) {
\t alert("error");
});
\t }
JSONで返されるデータの形式は次のとおりです。 https://pastebin.com/4XBR23ua
これは、あなたが配列の長さのためにそれを文字列化べきではありませんので、「セクション」は、既に配列であることを思わ
あなたが働いていないことを試してみましたか? –
私はjsonを壊そうとしています。そのために、私はそれを配列として呼び出す必要がありますが、私には正しい長さを与えていません。これは私が 'var sections_array = [];を試しているところです。 \t sections_array = JSON.stringify(data.sections); \t console.log(sections_array.length); ' – user2828442