0

I want to deserialize this json:

    [{"BuyPrice":0,"Description":null,"Id":3,"ReceptionId":7,"RejectPart":"
<Rejectedparameters>\u000d\u000a  <OutsideState>0<\/OutsideState>\u000d\u000a 
 <FastRPM>0<\/FastRPM>\u000d\u000a  <IdleRPM>0<\/IdleRPM>\u000d\u000a  
<FastLambda>0<\/FastLambda>\u000d\u000a  <FastCO>0<\/FastCO>\u000d\u000a  
<BackBrake>0<\/BackBrake>\u000d\u000a  <HandBrake>0<\/HandBrake>\u000d\u000a 
 <FrontBrake>0<\/FrontBrake>\u000d\u000a  
<BackLeftShockAbsorber>0<\/BackLeftShockAbsorber>\u000d\u000a  
<BackRightShockAbsorber>0<\/BackRightShockAbsorber>\u000d\u000a  
<FrontLeftShockAbsorber>0<\/FrontLeftShockAbsorber>\u000d\u000a  
<FrontRightShockAbsorber>0<\/FrontRightShockAbsorber>\u000d\u000a 
 <HandBrakeAcceleration>0<\/HandBrakeAcceleration>\u000d\u000a  
<BrakeAcceleration>0<\/BrakeAcceleration>\u000d\u000a  
<BackSideSlip>0<\/BackSideSlip>\u000d\u000a  <TotalWeight>0<\/TotalWeight>
\u000d\u000a  <BackWeight>0<\/BackWeight>\u000d\u000a  
<FrontWeight>0<\/FrontWeight>\u000d\u000a  <Lambda>0<\/Lambda>\u000d\u000a  
<NOX>0<\/NOX>\u000d\u000a  <CO2>0<\/CO2>\u000d
\u000a<\/Rejectedparameters>","Result":"Reject","SellPrice":220000,"State":nu
ll,"SubmitDatetime":"\/Date(1499677272213+0430)\/"}]

as you can see one of my columns is in XML format. My code to deserialize this json:

string result = ClientRequest.DownloadString(ServiceHostName + "/ReceptionHistoryService.svc/ReceptionHistoryByReceptionId/" + id);

var javascriptserializer = new JavaScriptSerializer();
return javascriptserializer.Deserialize<ReceptionHistory>(result);

but I get this error :

An unhandled exception of type 'System.InvalidOperationException' occurred in System.Web.Extensions.dll

Additional information: Type 'TRMStartPoint_NoCamera.DataContractModel.ReceptionHistory' is not supported for deserialization of an array.

Here is my receptionhistory class:

public class ReceptionHistory
{
    public Int64 Id { set; get; }
    public DateTime SubmitDatetime { set; get; }
    public Int64 ReceptionId { set; get; }
    public Int64 SellPrice { set; get; }
    public Int64 BuyPrice { set; get; }
    public string State { set; get; }
    public string Description { set; get; }
    public string RejectPart { set; get; }
    public string Result { set; get; }
}
2
  • Your JSON document is an array, indicated by the square brackets. Deserialize it to a collection Commented Jul 11, 2017 at 6:04
  • @SirRufo i added my receptionhistory class . Commented Jul 11, 2017 at 6:06

1 Answer 1

4

The error says that your type is not supposed to deserialize an array. Try to deserialize List<T>, instead of ReceptionHistory, like this:

javascriptserializer.Deserialize<List<ReceptionHistory>>(result);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.