.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Deserialize JSON object in C#

Posted By:      Posted Date: August 28, 2010    Points: 0   Category :.NET Framework
Hi, I am new to JSON and one of my service is returning JSON object as a string to my application. I need to Deserialize JSON object in C#. My JSON string is in the current format. string str = "{\"candidates\":[{\"address\":\"1580 MARKET ST, SAN FRANCISCO, CA, 94102\",\"location\":{\"x\":-122.42054,\"y\":37.7745960000001},\"score\":40,\"attributes\":{}},{\"address\":\"1576 MARKET ST, SAN FRANCISCO, CA, 94102\",\"location\":{\"x\":-122.420355,\"y\":37.7747030000001},\"score\":40,\"attributes\":{}}]}"; Can anyone please help me how to get all the address, locations, score and attributes from the above string. Thankyou, Ravi.

View Complete Post

More Related Resource Links

JSON Deserialize into Entity Framework Object and setting the DataMemberAttribute "Name="




I'm in the process of deserializing a JSON object into an Entity Framework object.  The property names in the JSON do not match up totally with the property names in the Entity Framework Objects. What I'd like to do is set "Name=" on the  "DataContractAttribute" for the table and the "DataMemberAttribute" for the properties in the Designer.cs file.  I tried setting these in the Designer.cs file manually just to see if it would work - which it did (using JSON.Net) but of course when I went into the .edmx designer I lost all my changes.  Is there a way to do this?


Thanks in advance

How could I deserialize a object which is serialized in JAVA??

When I try to do it with the code below. FileStream fileStream = new FileStream( "C:\\apps\\user.tmp", FileMode.Open, FileAccess.Read, FileShare.Read);     BinaryFormatter bf=new BinaryFormatter();     pd = (PianoData)bf.Deserialize(fileStream);     System.Console.WriteLine();     fileStream.Close(); Exception occurred as I had excepted. "The input stream is not a valid binary format."   I wonder if I can do it by another way

Sharepoint Designer issue "could not deserialize object"?

Hi there, I'm relatively new to Sharepoint in general but I've got an install of Sharepoint Foundation and I'm working my way through the book "Sharepoint 2010 Development." At any rate, I'm trying to create a workflow in Visio 2010 and then export that workflow into Sharepoint Designer 2010. However, when I try to import the .vwi file into Designer, I get a "Could not deserialize object. The type 'Microsoft.Office.Workflow.Actions.ApprovalTaskProcess' could not be resolved." This, of course, is because in Visio I have a Start Approval Process object.  Is this particular workflow item not available for Sharepoint Foundation? Does anyone have any idea why I'm getting this error? Any feedback is appreciated. Thanks, Jearod

Timer job intiation error: SharePoint cannot deserialize an object of type

Hi All, when i run a timer job (One-Time timer) it has added it to Timer Job definitions in the Central Administration. I have checked the Log file in 12 hive and found the following error..... "SharePoint cannot deserialize an object of type xyz.xyzJob, xyzTimer, Version=, Culture=neutral, PublicKeyToken=<token> on this machine. This typically occurs because the assembly containing this type is not installed on this machine. In this case, this message can be safely ignored. Otherwise, the assembly needs to be installed on this machine in a location that can be discovered by the .NET Framework." The above error says that the assembly is not added.... but it has been already added to the GAC. Can anyone guide me about the issue and how to resolve that........?

How to use return JSON object from web service as a declared Type?

Hi, I just hit the following issue: I am calling a web service that returns a serialized JSON object let's say: __type, FirstName, LastName (.net object Person with properties FirstName and LastName). __type's value is Test.Person I have created a JS object using Type.registerNameSpace/registerClass called Demo.Person and it is registered on the page using the ScriptManager. Everything is working fine; I am able to get data from the server on the call back. Is it possible to make the returned object from the web service be an instance of the declared JavaScript Demo.Person class? The idea would be to call a method like result.getFullName() on the client side without having to copy all the properties. This is just a simple scenario for more complex objects.   Thanks,   Teo

deserialize json string using javascript serializer problem



A json string was sent from client side to asmx web service.

Here json string is as below

"Name":"Ablation of Aflutter","BillingCode":"93651","ServiceCode":"1062","Value":1},
"Name":"Ablation of Atrial tachy","BillingCode":"93651","ServiceCode":"1062","Value":1},
"Name":"Ablation of AVN for CHB w/ or w/o temp pacer","BillingCode":"93650","ServiceCode":"1061","Value":1},
"Name":"Ablation of VT","BillingCode":"93652","ServiceCode":"1063","Value&q

JSON string to Object


If I have a  string  containing  valid JSON

how can I conver to an obect in c#?

Deserialize json into List


How can we Convert Json string into List<t> without using 3rd Party libraries. like json.net ..

Why cant we import the System.Runtime.Serialization.Json Library into codebehind.

I have a service wherei  am returning a json string of the List<t> to a wpf app..

There i need to convert back ...

Deserialize json into List


How can we Convert Json string into List<t> without using 3rd Party libraries. like json.net ..

Why cant we import the System.Runtime.Serialization.Json Library into codebehind.

I have a service wherei  am returning a json string of the List<t> to a wpf app..

There i need to convert back ...

How to get Datetime From Json Object.


Hi All

 I am calling an action from JQuery using $.getJSON() method.

This action returns a JsonResult object.

I am getting all the values correctly but not the Date Format.

Below is the Date format which i am getting.



But i want it like "10/15/2010 11:56 AM" this format.

How can i achieve it.....Please Help

Bind Repeater Control with JSON object


I have dropdown in the aspx page. I am calling JQuery on dropdown chnage and JQuery is calling GenericHandler.ashx . The Handler is retuns 

Serialize JSON  string. I ned to bind  my Repeater control with this JOSN object any can have idea . could you please help fro me. here I am giving  my sample aspx page code

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!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 runat="server">
    <title>Untitled Page</title>

<script type="text/javascript"  src="Shared/jquery-1.4.2.js" ></script>
<script type="text/javascript">
    var _entityId = 1;
    var _rowCount  = 5;
  var _pageIndex  = 8;

MVC3 + How to pass JSON Object as dictionorary object


In MVC3 Beta version i have action result same like

public ActionResult Save(Dictionary<string, string> dicObject)


I want to pass JSON Object in POST Method from javascript and need to get as dictionoray object


How can i do this? can you write example if possible?


Its urgent, please hep me




Problem in passing Json collection object from View to Action



I am trying to send json data from view to controller action.  But the issue is the data is not populating in the action parameter List<Score>.

View Model:
public class Score
   public int QuestionId { get; set; }
   public int PrevAnswerId { get; set; }
   public int CurrAnswerId { get; set; }
   public string CurrAnswerName { get; set; }

Json Data look like:
{QuestionId:1, PrevAnswerId:3,  CurrAnswerId:3,  CurrAnswerName:'Known to Broker'},
{QuestionId:2, PrevAnswerId:7,  CurrAnswerId:7,  CurrAnswerName:'Completed'},
{QuestionId:3, PrevAnswerId:10, CurrAnswerId:10, CurrAnswerName:'Report'}

On window load,  I will construct the Json object using "eval()" function and do some operation in the data before its save.

On Save Click, I will call the action through the ajax call.
        url: url,
        type: "GET",
        dataType: 'json',
        data: {score: ScoreJson},

Using DataContractJsonSerializer on dynamic JSON object


I'm using the DataContractJsonSerializer and the DataContract and DataMember class atrributes to serialize some JSON sent to me from a 3rd party javascript component. All is working well except the component sends some dynamic data.


ex. { "objects": [{"object1": "value"}, {"SomeOtherObject": "anotherValue"}] ... }


What are my options for serializing this if the "object1", "SomeOtherObject" are all dynamic and I can add them into the class that I serialize to. Is it possible to get the JSON Serializer to convert this to a Dictionary<string, string>??


Also I'm using C# 3.0 so dynamics is out.

Send JSON Object to WCF


I have a WCF returning JSON correctly, however this WCF now needs to be extended to allow JSON Serialized objects to be posted to it. I am using JQuery to serialize objects and post it to the WCF, and when I run the project in Debug the method SimpleSearch() is being called and an object is being instantiated, however the properties are all null. Is there an error taking place in the deserialization from JSON?

Below is an extract of my WCF file, below this is the JavaScript calling the WCF using JQuery

[ServiceContract(Namespace = "http://www.link.co.uk/")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class ATMService {        

        [WebInvoke(RequestFormat = WebMessageFormat.Json)]
        public void SimpleSearch(SimpleObj searchRequest) {
            // Once in here the searchRequest object both Name and Postcode are null      


    public class SimpleObj {
        public string Name { get; set; }
        public string PostCode{ get; set; }

function search() {   

    var searchRequest = new Object();
    searchRequest.Name = "Chris";

    var dataToSend = '{"searchRequest":[' + JSON.stringify(searchRequest) + ']}';

        type: "PO

How to return serialized JSON object from WCF



I am able to return the JSON string from the wcf. But i want to return the JSON object from wcf.

Is is possible to return the JSON object from the wcf? If yes , then how?


Thanks in advance..... 

Thinking about new C# method prototypes: object as dictionary

I recently had to write a small Flickr API. I know many .Net API for Flickr already exist but I needed one for a Silverlight application. Whatever, it's only about building some querystrings so I did it by myself. It's been an opportunity to think again about a classical question: how to pass parameters to a method ?

Imagine you have a generic method to call some Flickr functions.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend