Viv*_*jan 3 javascript asp.net-mvc jquery json
我有以下Json字符串.我希望使用'Key'得到'Value',就像这样
给'BtchGotAdjust'返回'Batch Got Adjusted';
var jsonstring=
[{"Key":"BtchGotAdjust","Value":"Batch Got Adjusted"},{"Key":"UnitToUnit","Value":"Unit To Unit"},]
Run Code Online (Sandbox Code Playgroud)
哇...看起来有点难!好像你需要稍微操纵一下.我们可以用这种方式创建一个新对象,而不是函数:
var jsonstring =
[{"Key":"BtchGotAdjust","Value":"Batch Got Adjusted"},{"Key":"UnitToUnit","Value":"Unit To Unit"},];
var finalJSON = {};
for (var i in jsonstring)
finalJSON[jsonstring[i]["Key"]] = jsonstring[i]["Value"];
Run Code Online (Sandbox Code Playgroud)
您可以使用它:
finalJSON["BtchGotAdjust"]; // Batch Got Adjusted
Run Code Online (Sandbox Code Playgroud)