tags:

views:

52

answers:

1

I'm really new too Json and I'm trying to call a Web Service.

When the service return an array of one element de json string for this array is without the [ ]. This cause a Exception in the serializer I use. (I use this one http://james.newtonking.com/)

My question is simple can I add something too tell to the deserializer to always take this section for a Array

In my code i have this model class

public class Company : BaseEntity
{
    #region Constructors
    public Company()
    {

    }

    public Company(int id, string name, string description)
    {
        Id = id;
        Name = name;
        Description = description;
    }
    #endregion

    #region Properties
    public int Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public List<Industry> IndustryList { get; set;}
    #endregion

}

And the Json for a company with one industry is

{"company":{"description":"Societe de Google","id":"0","industryList":{"id":"0","name":"Technologies Cool"},"name":"Google Inc."}

Maybe, i should change the serilizer tool too, I'm open too. All work find with other list of 2 or more elements or if I change the List for Industry but sometime I will receive more than one industry.

Thank you.

+2  A: 

Make your class

[DataContract]
public class Company : BaseEntity
{
    #region Constructors
    public Company()
    {

    }

    public Company(int id, string name, string description)
    {
        Id = id;
        Name = name;
        Description = description;
    }
    #endregion

    #region Properties
    [DataMember]
    public int Id { get; set; }
    [DataMember]
    public string Name { get; set; }
    [DataMember]
    public string Description { get; set; }
    [DataMember]
    public List<Industry> IndustryList { get; set;}
    #endregion

}
AsifQadri
This solution doesn't work, the problem is not on the deseriazaltion itself. It's the json don't contain [] for the industry list because they have only one element in that list. So in the deserialization progress, I get this exception: Cannot deserialize JSON object into type 'System.Collections.Generic.List`1[StockOverflow.Client.Logic.Models.Entities.Industry]'.
Yannick Charron