Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi to all..
Actually my scenario like this:
I took windows application..
I have one rest based json service by using that service i consumed.and i got json string(its is having so many columns are their).and now i deseralized that json string by using key value pair..i tried but not display output..

code like this:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Web.Script.Serialization;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)
{
string apiUrl = "http://api.geonames.org/citiesJSON?formatted=true&north=44.1&south=-9.9&east=-22.4&west=55.2&lang=de&username=demo&style=full";

Uri address = new Uri(apiUrl);

// Create the web request
System.Net.HttpWebRequest request = System.Net.WebRequest.Create(address) as System.Net.HttpWebRequest;
request.Method = "GET";
request.ContentType = "text/json";

using (System.Net.HttpWebResponse response = request.GetResponse() as System.Net.HttpWebResponse)
{
// Get the response stream
System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream());

string strOutput = reader.ReadToEnd();
string json =strOutput.ToString();

javaScriptSerializer js = new JavaScriptSerializer();
var object1 = js.Deserialize<dictionary><string,object>>(json);

foreach (KeyValuePair<string,object> result in object1)
{
Console.WriteLine("key:{0},key:{1}", result.Key, result.Value);

}

}
}
}
but console.writeline is not used.but how display output in textbox...if any body knows pls let me know..

Thanks in Advance.
Posted
Updated 20-Jul-11 20:07pm
v9
Comments
komalilella 20-Jul-11 8:27am    
did u send any solution?

1 solution

Your problem seems to lie here:

C#
object myobject=js.DeserializeObject(json);


Does this method return an object? Or does it return a Dictionary<string,object>? If it returns an object, then you need to convert that object into a Dictionary, so that you can iterate the collection using ForEach. Otherwise you need to declare the result of the method as a Dictionary and not an object.

Hope this helps
 
Share this answer
 

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