简体   繁体   English

修改Ionic Storage中object的部分内容

[英]Modify part of object in Ionic Storage

I'm trying to modify a part of object in Ionic storage.我正在尝试修改离子存储中 object 的一部分。 I've got this in Storage:我在存储中有这个:

key : object 
value : {a: "1", b: "2", c: "3"}

I tried to modify a value to 10 with this function:我尝试使用此 function 将值修改为 10:

modifyObject() {
    this.storage.get('object').then(valueStr => {
      let value = JSON.parse(valueStr);

      // Modify just that property
      value.a = '10';

      // Save the entire data again
      this.storage.set('object', JSON.stringify(value));
    });
  }

I've got this error when I try to execute mu function当我尝试执行 mu function 时出现此错误

ERROR Error: Uncaught (in promise): SyntaxError: Unexpected token o in JSON at position 1
SyntaxError: Unexpected token o in JSON at position 1

Your JSON in your value is malformed.您价值中的 JSON 格式不正确。

It must be something like this.它一定是这样的。

key : object 
value : {"a": "1", "b": "2", "c": "3"}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM