車と呼ばれるオブジェクトの作成:
function car(temp){
this.brand=temp[0];
this.color=temp[1];
this.year=temp[2];
}
var temp = ['Skoda', 'Red', '2012'];
car = new car(temp);
localStorageから読み取った後、オブジェクトを設定して文字列化します。
localStorage.setItem('car',car); car = localStorage.getItem('car'); car = JSON.stringify(car);
stringify後の車----------------->[objectObject] at file:/// android_asset / www / .. ..
オブジェクトをStringifyし、その後、オブジェクトをlocalStorageに設定します。
localStorage.setItem('car',JSON.stringify(car)); car = localStorage.getItem('car');
stringify後の車----------------->"{\"brand \ ":\" Skoda \ "、\" color \ ":\" Red \ "、\" year \ ":\" 2012 \ "}" at file:/// android_asset / www/..。
質問1:オブジェクトを文字列化するときの順序が異なるのはなぜですか?
質問2:なぜそのような文字列化されたオブジェクトを使用できないのですか?
08-21 11:49:14.860: I/Web Console(9642): car after stringify-----------------> {"brand":"Skoda","color":"Red","year":"2012"}
console.log( "car.brand ----->" + car.brand); car.name -----> undefined