如何将json一种格式转换为另一种格式

如何将json一种格式转换为另一种格式,json,json.net,Json,Json.net,您好,我想将json从一种格式转换为另一种格式,如下所示 我尝试使用Json.Net插件,但找不到解决方案 [ { "bundleKey": "title", "bundleValue": "Manage cost code", }, { "bundleKey": "name", "bundleValue": "steve", }] 要转换为以下格式吗 [{"title":"Manage cost code"},{"name":"steve"}] 我尝

您好,我想将json从一种格式转换为另一种格式,如下所示 我尝试使用Json.Net插件,但找不到解决方案

[
{

    "bundleKey": "title",
    "bundleValue": "Manage cost code",

},
{

    "bundleKey": "name",
    "bundleValue": "steve",

}]
要转换为以下格式吗

[{"title":"Manage cost code"},{"name":"steve"}]
我尝试使用以下链接

私有静态列表转换(列表jsonNode){
if(jsonNode==null)
返回null;
列表结果=新建ArrayList();
for(映射json:jsonNode){
Map tmp=newhashmap();
putVaue(tmp、json);
结果:添加(tmp);
}
返回结果;
}
私有静态无效putVaue(映射结果,
映射(jsonNode){
String key=(String)jsonNode.get(“bundleKey”);
Object value=jsonNode.get(“bundleValue”);
结果。输入(键、值);
}
私有静态列表转换(列表jsonNode){
if(jsonNode==null)
返回null;
列表结果=新建ArrayList();
for(映射json:jsonNode){
Map tmp=newhashmap();
putVaue(tmp、json);
结果:添加(tmp);
}
返回结果;
}
私有静态无效putVaue(映射结果,
映射(jsonNode){
String key=(String)jsonNode.get(“bundleKey”);
Object value=jsonNode.get(“bundleValue”);
结果。输入(键、值);
}

这里是一种使用Json.Net将Json从一种格式转换为另一种格式的快速方法(假设输入是有效的Json——正如您所发布的,bundleValue后面有额外的逗号,我在下面的代码中删除了这些逗号):

输出:

[{"title":"Manage cost code"},{"name":"steve"}]

下面是一种使用Json.Net将Json从一种格式转换为另一种格式的快速方法(假设输入是有效的Json——正如您所发布的,BundleValue后面有额外的逗号,我在下面的代码中删除了这些逗号):

输出:

[{"title":"Manage cost code"},{"name":"steve"}]

输入不是有效的JSON。有尾随逗号。输入不是有效的JSON。有尾随的逗号。这是.NET还是Java?这是.NET还是Java?嗨,为什么要将Json初始化为字符串。我从泛型中获取Json。所以我在JArray array=JArray.Parse(Json)行中得到错误;作为参数,无法将模型转换为stringYa,但我希望它在asp.net中正常工作。这在控制台应用程序中正常工作上述代码中除了
console.WriteLine()之外没有任何内容
这会阻止它在ASP.NET.hi中使用,为什么要将Json初始化为字符串。我是从泛型中获取Json的。所以我在JArray array=JArray.Parse(Json)行中获取错误;作为一个参数,无法将模型转换为stringYa。它工作正常。但我希望在asp.net中使用它。这在控制台应用程序中工作正常。除了
console.WriteLine()
之外,上述代码中没有任何内容阻止它在asp.net中使用。
[{"title":"Manage cost code"},{"name":"steve"}]