I am using json.net to convert currency rates to JSON format.
In the C# entity, there are Name and Value properties; where Name represents currencies like USD, GBP, etc. and Value holds the currency rate.
Since I do not know the index of different currencies, I want to retrieve a currency in JavaScript by simply declaring var a = obj["USD"];
instead of iterating through an array to find array[i].name == "USD"
. The default output of
JsonConvert.SerializeObject(currencyList);
is as follows:
[
{"name": "one", "pId": "foo1", "cId": "bar1"},
{"name": "two", "pId": "foo2", "cId": "bar2"},
{"name": "three", "pId": "foo3", "cId": "bar3"}
]
However, I would prefer the output to be structured like this:
{
"one": {"pId": "foo1", "cId": "bar1"},
"two": {"pId": "foo2", "cId": "bar2"},
"three": {"pId": "foo3", "cId": "bar3"}
}
I am wondering if it is possible to achieve this formatting using json.net, or if I need to create my own parser?