JSON的jQuery设置值:以字符串形式提供的路径 [英] JQuery set value for the json: path provided as string

查看:124
本文介绍了JSON的jQuery设置值:以字符串形式提供的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串,其中包含嵌套json的路径,我需要在其中更新值

I have a string that carry the path of a nested json, where I need to update a value

var path = 'p_Data[0]["BusinessUnit"][0]["BusinessUnit"]' 

如果我评估此路径,我将获得"Unit1"的值.我需要使用已关闭"更新值"Unit1"并检索原始数据,即p_Data

if i evaluate this path I get value as 'Unit1'. I need to update the value 'Unit1' with 'Closed' and retrieve the original data ie, p_Data

我尝试了eval(path = 'Closed'),但是没有用.

I tried eval(path = 'Closed'), but didn't work.

该怎么做?

推荐答案

eval(path + "='Closed'");

但是请看一下这个线程:为什么使用JavaScript eval函数是个坏主意吗?.

But have a look at this thread: Why is using the JavaScript eval function a bad idea?.

这篇关于JSON的jQuery设置值:以字符串形式提供的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆