How to dynamically get items from Json feed

I need to pull and display some json data from a google stock feed:

https://finance.google.com/finance/info?client=ig&q=NYSE:BHP

The only catch is I don't know what the data is. The customer would like to pass in a list of comma separated values to tell my code what items to pull.I would therefore plan to pass in an array of named items to tell the feed which items I want values for, so in theory to match the incoming values with the equivalent json item names. It wont always be the same items or number of items.

How can I do this dynamically (I am using json.net) ?

Sample Json Data:

[{
    "id": "4905",
    "t": "BHP",
    "e": "NYSE",
    "l": "26.90",
    "l_fix": "26.90",
    "l_cur": "26.90",
    "s": "0",
    "ltt": "6:01PM EST",
    "lt": "Dec 2, 6:01PM EST",
    "lt_dts": "2015-12-02T18:01:42Z",
    "c": "-0.41",
    "c_fix": "-0.41",
    "cp": "-1.50",
    "cp_fix": "-1.50",
    "ccol": "chr",
    "pcls_fix": "27.31"
}]

Sample of CSV values the user might pass in:

t, e, l, cp_fix

Answers


You can use the json class from System.Web.Helpers namespace to deserialize json string into a dynamic object. like below:

dynamic Data = Json.Decode(json);

It is included with the MVC framework as an additional download to the .NET 4 framework. Than you can access the properties you want using Data.PropertyName


Need Your Help

Preserve li width when child element hidden

html css

I have a simple pagination control like below

Parsing wrong data from Json in android

android json parsing

I am parsing the json data from php server but what value I am getting in each tag is not the actual value of that tag. Value get switched between each tags.