更改 Android 应用程序中 json 对象的属性 (Titanium)
您好,我正在使用 Titanium 开发 Android 应用程序。我想更改 json 对象的特定属性的值。我尝试了以下代码:
var row_jsonfeed = this.responseText;
var jsonfeed = eval('('+row_jsonfeed+')');
我的 jsonfeed 对象如下所示:
{"feeds":
[
{"username":"abc","user":"abc","feed":{"description":"dss","id":660,"user_id":1}},
{"username":"bcd","user":"bcd","feed":{"description":"dddd","id":659,"user_id":1}}
]
}
我想更改 用户名 值,所以我尝试像这:
jsonfeed.feeds[0].username = "xyz";
alert(jsonfeed.feeds[0].username);
但它不起作用。它没有给我更改用户名的值。任何其他替代方法可以做到这一点。除了 eval 之外,我还尝试了 JSON.parse 但这也不起作用。所以我需要正确的方法来做到这一点。提前谢谢您。
Hi I am developing Android application using Titanium.I want to change value of particular attributes of json object.I tried following code :
var row_jsonfeed = this.responseText;
var jsonfeed = eval('('+row_jsonfeed+')');
my jsonfeed object look like this :
{"feeds":
[
{"username":"abc","user":"abc","feed":{"description":"dss","id":660,"user_id":1}},
{"username":"bcd","user":"bcd","feed":{"description":"dddd","id":659,"user_id":1}}
]
}
I want to change username value so I tried like this:
jsonfeed.feeds[0].username = "xyz";
alert(jsonfeed.feeds[0].username);
But it's not working.It not giving me changed value of username.Any other alternative way to do this. Instead of eval I also tried JSON.parse but that also not working.So i need proper way to do this.Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题出在你对 eval 的调用上。您忘记连接括号:
I think the problem is with your call to eval. You forgot to concatenate your parens: