我有以下 Json 字符串。我想使用“Key”获取“Value”,比如
给出“BtchGotAdjust”返回“Batch Got Adjusted”;
var jsonstring=
[{"Key":"BtchGotAdjust","Value":"Batch Got Adjusted"},{"Key":"UnitToUnit","Value":"Unit To Unit"},]
最佳答案
哇...看起来有点硬!似乎您需要稍微操纵一下。我们可以这样创建一个新对象,而不是函数:
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"];
您可以使用它:
finalJSON["BtchGotAdjust"]; // Batch Got Adjusted
关于javascript - 如何在 Javascript/Jquery 中使用 'Value' 从 json 获取 'Key',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25503627/