From: Matthijs de Z on
Hi,

I'm having difficulties reading a resultset that yahoo provides using
when you send this request:
http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=yahoo&callback=YAHOO.Finance.SymbolSuggest.ssCallback
(used in an example on http://stackoverflow.com/questions/885456/stock-ticker-symbol-lookup-api)

I've modified the result to a const string like this:
const string myTest = "{\"ResultSet\":{\"Query\":\"ya\",\"Result\":
[{\"symbol\":\"YHOO\",\"name\": \"Yahoo! Inc.\",\"exch\": \"NMS\",
\"type\": \"S\",\"exchDisp\":\"NASDAQ\"},{\"symbol\":\"AUY\",\"name\":
\"Yamana Gold, Inc.\",\"exch\": \"NYQ\",\"type\": \"S\",\"exchDisp\":
\"NYSE\"},{\"symbol\":\"YZC\",\"name\": \"Yanzhou Coal Mining Co. Ltd.
\",\"exch\": \"NYQ\",\"type\": \"S\",\"exchDisp\":\"NYSE\"},{\"symbol
\":\"YRI.TO\",\"name\": \"YAMANA GOLD INC COM NPV\",\"exch\": \"TOR\",
\"type\": \"S\",\"exchDisp\":\"Toronto\"},{\"symbol\":\"8046.TW\",
\"name\": \"NAN YA PRINTED CIR TWD10\",\"exch\": \"TAI\",\"type\": \"S
\",\"exchDisp\":\"Taiwan\"},{\"symbol\":\"600319.SS\",\"name\":
\"WEIFANG YAXING CHE 'A'CNY1\",\"exch\": \"SHH\",\"type\": \"S\",
\"exchDisp\":\"Shanghai\"},{\"symbol\":\"1991.HK\",\"name\": \"TA YANG
GROUP\",\"exch\": \"HKG\",\"type\": \"S\",\"exchDisp\":\"Hong Kong\"},
{\"symbol\":\"1303.TW\",\"name\": \"NAN YA PLASTIC TWD10\",\"exch\":
\"TAI\",\"type\": \"S\",\"exchDisp\":\"Taiwan\"},{\"symbol\":\"0294.HK
\",\"name\": \"YANGTZEKIANG\",\"exch\": \"HKG\",\"type\": \"S\",
\"exchDisp\":\"Hong Kong\"},{\"symbol\":\"YAVY\",\"name\": \"Yadkin
Valley Financial Corp.\",\"exch\": \"NMS\",\"type\": \"S\",\"exchDisp
\":\"NASDAQ\"}]}}";

How can I get the tickers and names in a dictionary (or some object
like that) so I can use it as a dataresource for a textfield
(autocomplete).

I've tried some linq, but it seems that there's no linq functionallity
to Json and I don't know how to get the data needed out of this
resultset.

Any help would be appreciated,.
From: Arne Vajhøj on
On 21-06-2010 04:49, Matthijs de Z wrote:
> Hi,
>
> I'm having difficulties reading a resultset that yahoo provides using
> when you send this request:
> http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=yahoo&callback=YAHOO.Finance.SymbolSuggest.ssCallback
> (used in an example on http://stackoverflow.com/questions/885456/stock-ticker-symbol-lookup-api)
>
> I've modified the result to a const string like this:
> const string myTest = "{\"ResultSet\":{\"Query\":\"ya\",\"Result\":
> [{\"symbol\":\"YHOO\",\"name\": \"Yahoo! Inc.\",\"exch\": \"NMS\",
> \"type\": \"S\",\"exchDisp\":\"NASDAQ\"},{\"symbol\":\"AUY\",\"name\":
> \"Yamana Gold, Inc.\",\"exch\": \"NYQ\",\"type\": \"S\",\"exchDisp\":
> \"NYSE\"},{\"symbol\":\"YZC\",\"name\": \"Yanzhou Coal Mining Co. Ltd.
> \",\"exch\": \"NYQ\",\"type\": \"S\",\"exchDisp\":\"NYSE\"},{\"symbol
> \":\"YRI.TO\",\"name\": \"YAMANA GOLD INC COM NPV\",\"exch\": \"TOR\",
> \"type\": \"S\",\"exchDisp\":\"Toronto\"},{\"symbol\":\"8046.TW\",
> \"name\": \"NAN YA PRINTED CIR TWD10\",\"exch\": \"TAI\",\"type\": \"S
> \",\"exchDisp\":\"Taiwan\"},{\"symbol\":\"600319.SS\",\"name\":
> \"WEIFANG YAXING CHE 'A'CNY1\",\"exch\": \"SHH\",\"type\": \"S\",
> \"exchDisp\":\"Shanghai\"},{\"symbol\":\"1991.HK\",\"name\": \"TA YANG
> GROUP\",\"exch\": \"HKG\",\"type\": \"S\",\"exchDisp\":\"Hong Kong\"},
> {\"symbol\":\"1303.TW\",\"name\": \"NAN YA PLASTIC TWD10\",\"exch\":
> \"TAI\",\"type\": \"S\",\"exchDisp\":\"Taiwan\"},{\"symbol\":\"0294.HK
> \",\"name\": \"YANGTZEKIANG\",\"exch\": \"HKG\",\"type\": \"S\",
> \"exchDisp\":\"Hong Kong\"},{\"symbol\":\"YAVY\",\"name\": \"Yadkin
> Valley Financial Corp.\",\"exch\": \"NMS\",\"type\": \"S\",\"exchDisp
> \":\"NASDAQ\"}]}}";
>
> How can I get the tickers and names in a dictionary (or some object
> like that) so I can use it as a dataresource for a textfield
> (autocomplete).
>
> I've tried some linq, but it seems that there's no linq functionallity
> to Json and I don't know how to get the data needed out of this
> resultset.
>
> Any help would be appreciated,.

You should be able to write a data class and then use
JavaScriptSerializer Deserialize to get the data in
format that can easily be processed.

Arne

From: Arne Vajhøj on
On 21-06-2010 17:44, Arne Vajh�j wrote:
> On 21-06-2010 04:49, Matthijs de Z wrote:
>> I'm having difficulties reading a resultset that yahoo provides using
>> when you send this request:
>> http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=yahoo&callback=YAHOO.Finance.SymbolSuggest.ssCallback
>>
>> (used in an example on
>> http://stackoverflow.com/questions/885456/stock-ticker-symbol-lookup-api)
>>
>> I've modified the result to a const string like this:
>> const string myTest = "{\"ResultSet\":{\"Query\":\"ya\",\"Result\":
>> [{\"symbol\":\"YHOO\",\"name\": \"Yahoo! Inc.\",\"exch\": \"NMS\",
>> \"type\": \"S\",\"exchDisp\":\"NASDAQ\"},{\"symbol\":\"AUY\",\"name\":
>> \"Yamana Gold, Inc.\",\"exch\": \"NYQ\",\"type\": \"S\",\"exchDisp\":
>> \"NYSE\"},{\"symbol\":\"YZC\",\"name\": \"Yanzhou Coal Mining Co. Ltd.
>> \",\"exch\": \"NYQ\",\"type\": \"S\",\"exchDisp\":\"NYSE\"},{\"symbol
>> \":\"YRI.TO\",\"name\": \"YAMANA GOLD INC COM NPV\",\"exch\": \"TOR\",
>> \"type\": \"S\",\"exchDisp\":\"Toronto\"},{\"symbol\":\"8046.TW\",
>> \"name\": \"NAN YA PRINTED CIR TWD10\",\"exch\": \"TAI\",\"type\": \"S
>> \",\"exchDisp\":\"Taiwan\"},{\"symbol\":\"600319.SS\",\"name\":
>> \"WEIFANG YAXING CHE 'A'CNY1\",\"exch\": \"SHH\",\"type\": \"S\",
>> \"exchDisp\":\"Shanghai\"},{\"symbol\":\"1991.HK\",\"name\": \"TA YANG
>> GROUP\",\"exch\": \"HKG\",\"type\": \"S\",\"exchDisp\":\"Hong Kong\"},
>> {\"symbol\":\"1303.TW\",\"name\": \"NAN YA PLASTIC TWD10\",\"exch\":
>> \"TAI\",\"type\": \"S\",\"exchDisp\":\"Taiwan\"},{\"symbol\":\"0294.HK
>> \",\"name\": \"YANGTZEKIANG\",\"exch\": \"HKG\",\"type\": \"S\",
>> \"exchDisp\":\"Hong Kong\"},{\"symbol\":\"YAVY\",\"name\": \"Yadkin
>> Valley Financial Corp.\",\"exch\": \"NMS\",\"type\": \"S\",\"exchDisp
>> \":\"NASDAQ\"}]}}";
>>
>> How can I get the tickers and names in a dictionary (or some object
>> like that) so I can use it as a dataresource for a textfield
>> (autocomplete).
>>
>> I've tried some linq, but it seems that there's no linq functionallity
>> to Json and I don't know how to get the data needed out of this
>> resultset.
>>
>> Any help would be appreciated,.
>
> You should be able to write a data class and then use
> JavaScriptSerializer Deserialize to get the data in
> format that can easily be processed.

Example code:

using System;
using System.Linq;
using System.Collections.Generic;
using System.Web.Script.Serialization;

namespace E
{
public class Entry
{
public string symbol { get; set; }
public string name { get; set; }
public string exch { get; set; }
public string type { get; set; }
public string exchDisp { get; set; }
}
public class ResultSetData
{
public string Query { get; set; }
public List<Entry> Result { get; set; }
}
public class Data
{
public ResultSetData ResultSet { get; set; }
}
public class Program
{
public static void Main(string[] args)
{
string s = "{\"ResultSet\":{\"Query\":\"ya\",\"Result\":
[{\"symbol\":\"YHOO\",\"name\": \"Yahoo! Inc.\",\"exch\": \"NMS\",
\"type\": \"S\",\"exchDisp\":\"NASDAQ\"},{\"symbol\":\"AUY\",\"name\":
\"Yamana Gold, Inc.\",\"exch\": \"NYQ\",\"type\": \"S\",\"exchDisp\":
\"NYSE\"},{\"symbol\":\"YZC\",\"name\": \"Yanzhou Coal Mining Co. Ltd.
\",\"exch\": \"NYQ\",\"type\": \"S\",\"exchDisp\":\"NYSE\"},{\"symbol
\":\"YRI.TO\",\"name\": \"YAMANA GOLD INC COM NPV\",\"exch\": \"TOR\",
\"type\": \"S\",\"exchDisp\":\"Toronto\"},{\"symbol\":\"8046.TW\",
\"name\": \"NAN YA PRINTED CIR TWD10\",\"exch\": \"TAI\",\"type\": \"S
\",\"exchDisp\":\"Taiwan\"},{\"symbol\":\"600319.SS\",\"name\":
\"WEIFANG YAXING CHE 'A'CNY1\",\"exch\": \"SHH\",\"type\": \"S\",
\"exchDisp\":\"Shanghai\"},{\"symbol\":\"1991.HK\",\"name\": \"TA YANG
GROUP\",\"exch\": \"HKG\",\"type\": \"S\",\"exchDisp\":\"Hong Kong\"},
{\"symbol\":\"1303.TW\",\"name\": \"NAN YA PLASTIC TWD10\",\"exch\":
\"TAI\",\"type\": \"S\",\"exchDisp\":\"Taiwan\"},{\"symbol\":\"0294.HK
\",\"name\": \"YANGTZEKIANG\",\"exch\": \"HKG\",\"type\": \"S\",
\"exchDisp\":\"Hong Kong\"},{\"symbol\":\"YAVY\",\"name\": \"Yadkin
Valley Financial Corp.\",\"exch\": \"NMS\",\"type\": \"S\",\"exchDisp
\":\"NASDAQ\"}]}}";
Console.WriteLine(s);
JavaScriptSerializer jss = new JavaScriptSerializer();
Data d = jss.Deserialize<Data>(s);
foreach(var sym in d.ResultSet.Result.Where(r => r.exch ==
"HKG"))
{
Console.WriteLine(sym.name + " @ " + sym.exchDisp);
}
Console.ReadKey();
}
}
}

Arne


From: Matthijs de Z on
On 22 jun, 02:31, Arne Vajhøj <a...(a)vajhoej.dk> wrote:
> On 21-06-2010 17:44, Arne Vajh j wrote:

[Arne's code]

Hi Arne,

Works great!!!
Thanks a lot for helping out.

Where did you get this knowledge from? Do you have / know a specific
tutorial somewhere on the web?
Kind regards,

Matthijs

> Arne- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -

From: Arne Vajhøj on
On 22-06-2010 05:03, Matthijs de Z wrote:
> On 22 jun, 02:31, Arne Vajh�j<a...(a)vajhoej.dk> wrote:
>> On 21-06-2010 17:44, Arne Vajh j wrote:
>
> [Arne's code]

> Works great!!!

> Where did you get this knowledge from? Do you have / know a specific
> tutorial somewhere on the web?

I reused some code that I wrote for another problem in
another forum and then I looked for the class via
Google because someone in a third forum had told me
that .NET had builtin support for JSON.

Arne