Click here to Skip to main content
16,019,109 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how I can receive and display JSON data in my web service in C # ?

I am in the web page service (page.asmx) and I want write a function that receives and displays the JSON data.

The data:

[{"id":"1","name":"Civil","litigation":"yes","corporate":"yes"},{"id":"2","name":"Criminal","litigation":"yes","corporate":"yes"}...
Posted
Comments
Kornfeld Eliyahu Peter 1-Jul-14 6:45am    
Receives from where and displays on what?
Member 10872485 1-Jul-14 7:00am    
I'm sorry.

Receive a JSON data from a web application (I have a URL access).

In fact, the mission is to receive data from a web application in a desktop application by intermediate a web service, so now, I am in the web service and I am looking to write a function that receive the JSON data.

I hope that my idea is clear now and.
Thank you in advance
Kornfeld Eliyahu Peter 1-Jul-14 7:06am    
You wrote: 'from a web application (I have a URL access)' - do you mean a web-service?
Member 10872485 1-Jul-14 7:31am    
No, what I meant to say that the JSON data come from a web application, and I want to write a function in a web service to retrieve this data.
I say a URL to access, ie these data will be sent as JSON from this URL.
exemple for URL (http://localhost:8081/xxxxx/case_types/load_all)

1 solution

If I got you right you need no any intermediate web service.
You can use WebClient[^] class to download the JSON directly from the given URL...
Use WebClient.DownloadData(), than convert the resulting byte array to string and use it!
 
Share this answer
 
Comments
Member 10872485 1-Jul-14 8:22am    
But the function from this class returns me the data in bytes, I tried to convert their string, but unfortunately I have not received the data provided
Kornfeld Eliyahu Peter 1-Jul-14 8:32am    
Use this: http://msdn.microsoft.com/en-us/library/744y86tc(v=vs.110).aspx
Member 10872485 1-Jul-14 10:31am    
Excuse me, but it gives me in the header of the page
"This XML File does not APPEAR to have any style information Associated with it. The document tree is shown below"
and writing the tag in XML !

The date is :
{"id":"1","name":"Civil","litigation":"yes","corporate":"yes"},{"id":"2","name":"Criminal","litigation":"yes","corporate":"yes"}, ...

The code is :
string jsonData = "";
WebClient wc = new WebClient();
jsonData = wc.DownloadData("http://localhost:8081/xxxx/case_types/load_all");
jsonData = System.Text.Encoding.UTF8.GetString(buffer);
return jsonData;
Kornfeld Eliyahu Peter 1-Jul-14 11:54am    
When you open that URL in a browser what do you get?
Member 10872485 2-Jul-14 1:33am    
it gives me the data in this form :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>App4Legal</title> <base href="http://localhost:8081/app4legal.v4.2.4/" /> <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> <link rel="shortcut icon" type="image/x-icon"...

under title :
This XML file does not appear to have any style information associated with it. The document tree is shown below.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900