1

My Json string:

    jsonString ="{"GetStatusResult":[{"CaseCompleteInd":"N","CaseNbr":"999999","InSurgeryNowInd":"Y","InRoomNowInd":"N"}]}";

My classes:

public class GetStatusResult
{
    public List<CaseModel> caseDetails { get; set; }
}

public class CaseModel
{
    public string CaseCompleteInd { get; set; }
    public string CaseConfirmNbr { get; set; }

    public string InSurgeryNowInd { get; set; }
    public string InRoomNowInd{ get; set; }
}

}

My code:

    GetStatusResult caseInfo = new GetStatusResult();

    JavaScriptSerializer jsSerializer = new JavaScriptSerializer();

    caseInfo = jsSerializer.Deserialize<GetStatusResult>(jsonString);

My Problem:

The object is always returning as NULL and the CaseModel details are not being populated. The JSON string obviously has data, but I feel that my class structure is somehow messed up with the root level class. It appears similar to other examples posted here and elsewhere, so I'm at a loss right now. Any help is greatly appreciated.

1
  • I presume you mean the caseInfo object is returning null? Where are you referencing the CaseModel class? I'm not seeing it. Commented Jun 4, 2012 at 21:55

1 Answer 1

2

If you modify your JSON string to

jsonString ="{"caseDetails":[{"CaseCompleteInd":"N","CaseNbr":"999999","InSurgeryNowInd":"Y","InRoomNowInd":"N"}]}";

then it should work.

Properties of JSON object correspond to the properties of .NET object having the same name.

Sign up to request clarification or add additional context in comments.

1 Comment

Perfect. Thank you. I was not aware the naming had to be the same.

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.