JSON将字典转换为键值对列表 [英] JSON convert dictionary to a list of key value pairs

查看:898
本文介绍了JSON将字典转换为键值对列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字典< string,string>

I have a Dictionary <string, string>

如果我是Json.对此进行编码,我会得到{"Apple":"Apples","Orange":"Oranges"}

If I Json.Encode this I get {"Apple":"Apples","Orange":"Oranges"}

我该如何做到这一点:-

How I can get this to:-

[{ value: "Apples", key: "Apple" }, { value: "Oranges", key: "Orange"}]

最好使用Newtonsoft.Json或jQuery

Preferably using Newtonsoft.Json or jQuery

推荐答案

在传递给JSON序列化程序之前,将其转换为键值对列表:

Convert it to a list of key value pairs before passing to the JSON serializer:

JsonConvert.SerializeObject(new List<KeyValuePair<string,string>>(dictionary));

这篇关于JSON将字典转换为键值对列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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