3

I need to access data records from salesforce object. I got the json response.The json document is given below,

{
"totalSize":2,
"done":true,
"records":
    [{"attributes":
      {
    "type":"Session__c",
    "url":"/services/data/v20.0/sobjects/Session__c/a069000000RW12OAAT"
      },
    "Course__r":
      {
        "attributes":
            {"type":"Course__c",
            "url":"/services/data/v20.0/sobjects/Course__c/a079000000EqVgwAAF"
            },
        "Name":"aaaaaaaa",
        "Type__c":"NetSuite"}},

    {"attributes":
        {
            "type":"Session__c",
            "url":"/services/data/v20.0/sobjects/Session__c/a069000000RW1ymAAD"
        },
        "Course__r":
        {
        "attributes":
            {
            "type":"Course__c",
            "url":"/services/data/v20.0/sobjects/Course__c/a079000000EqVkOAAV"
            },
        "Name":"hhhhhhh",
        "Type__c":"RubyonRails"}
    }]

}

The use the following classes for in .net for deserializing it.

 public class coursedetails
{
    public string done { get; set; }
    public string totalSize { get; set; }
    public Records records { get; set; }

}
public class Records 
{
public Attributes attributes{ get; set; }
public Cource_r Cource_r { get; set; }
public string Type_c { get; set; }
}
public class Cource_r
{
    public string Name { get; set; }
    public string Type_c { get; set; }
}

public class Attributes 
{
    public string type { get; set; }
    public string url { get; set; }

}

/************* code for deserializing

  JavaScriptSerializer ser1 = new JavaScriptSerializer();
    record = ser1.Deserialize<coursedetails>(s);

But i cant deserialize it due to an error.An exception of type 'System.InvalidOperationException' occurred in System.Web.Extensions.dll but was not handled in user code

Additional information: Type 'connect+Records' is not supported for deserialization of an array.What is wrong with my code.

1
  • Please try to only select descriptive tags for your question. This will help attract the right people to your question :) Commented Jan 14, 2014 at 11:00

1 Answer 1

3

Make

public class coursedetails
{
    public string done { get; set; }
    public string totalSize { get; set; }
    public Records records { get; set; }

}

as

public class coursedetails
{
    public string done { get; set; }
    public string totalSize { get; set; }
    public Records[] records { get; set; }

}

ie make records as an array of Records

1
  • Eagle eyes... well spotted sir! Commented Jan 14, 2014 at 15:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .