سؤال

I created a user control called ticker that is used in my trading program. It takes a url property that controls where it gets its prices from. A few example urls are:

coinbase.com/api/v1/prices/buy
btc-e.com/api/2/btc_usd/ticker
www.bitstamp.net/api/ticker/

I want the user to be able to change which exchange provides json object and also specify the javascript expression to find the value like this:

json.total.amount
json.last.buy
json.last

etc. I can find a ton of dynamic examples where dynamic objects are being created, but the javascript expression is known in advance and the value is referenced in C# with json.last for exmple in C#. I will not know what the expression will be, so how do I get c# to evaluate my expression and store the results in a variable?

هل كانت مفيدة؟

المحلول

json.net library allow you to parse json string to dynamic object easily.

dynamic d = JObject.Parse("{}");

For more information, LINQ to JSON

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top