3

I need to get json data from an external domain. I used webrequest to get the response from a website. heres the code:

var search = umbraco.library.Request("search");
string Url = "http://ff.ss.dk/Suggest.ff?username=us&password=pass&channel=dk&format=JSON&query="+search;
WebRequest webRequest = WebRequest.Create(Url);
WebResponse response = webRequest.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);

this way i am getting an output like this

[{"hitCount":0,"imageURL":"","query":"Atrix h\u00E5ndcreme Dobbeltvirkende /100 Ml","type":"productName"},{"hitCount":0,"imageURL":"","query":"V\u00E6gur magnetisk attraction","type":"productName"},{"hitCount":0,"imageURL":"","query":"Bic kuglepen Atlantis , bl\u00E5","type":"productName"},{"hitCount":0,"imageURL":"","query":"Laminering AT1256 31cm x30m A3","type":"productName"}]

I want to get this output data in JSON object format, that i can use this in my java script functions. i think the output data is in inappropriate format because i have used streamreader function to get data.is there any idea to solve this issue?

3
  • Have you tried using Json.Net to serialize that content? Commented Aug 7, 2012 at 12:31
  • how is the output data 'inappropriate'? it appears to be valid JSON when validated at jsonformatter.curiousconcept.com Commented Aug 7, 2012 at 12:43
  • @wal:data is in string format i need to convert it to json object Commented Aug 10, 2012 at 5:58

2 Answers 2

7

This data can be converted to json format using jQuery.parseJSON.

 var obj = JSON.parse(data);

then we can access data like

 obj[0].id

thanks to all.

Sign up to request clarification or add additional context in comments.

Comments

0

You seem to be missing an array name specifier, for example, this works:

{arrayName:[{"hitCount":0,"imageURL":"","query":"Atrix h\u00E5ndcreme Dobbeltvirkende /100 Ml","type":"productName"},{"hitCount":0,"imageURL":"","query":"V\u00E6gur magnetisk attraction","type":"productName"},{"hitCount":0,"imageURL":"","query":"Bic kuglepen Atlantis , bl\u00E5","type":"productName"},{"hitCount":0,"imageURL":"","query":"Laminering AT1256 31cm x30m A3","type":"productName"}]}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.