2

I have a JSON encoded string. It looks like this:

{"jsonrpc":"2.0","method":"test","params":["80851851709e01bc9453cced585a7bca","this"],"id":3}

I cannot get access to 'params' with C# for some reason. The object comes back null. Here is the code I am using:

public class Access : System.Web.Services.WebService
{

    [WebMethod]
    public string EntryMethod(string json)
    {
        Requests d = JsonConvert.DeserializeObject<Requests>(json);
        return "done";
    }
}
public class Requests
{
    public string jsonrpc { get; set; }
    public string method { get; set; }
    public List<string> param { get; set; }
    public string id { get; set; }
}

Any ideas?

1
  • your property is called param not params. I guess that is the reason Commented Oct 3, 2012 at 15:10

1 Answer 1

3

Because of wrong typo, should be:

ParamS // Add one more S

So, your class should be:

public class Requests
{
    public string jsonrpc { get; set; }
    public string method { get; set; }
    public List<string> @params { get; set; }
    public string id { get; set; }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Just being pernickety here...but I wouldn't advise using a reserved keyword as a property name. Might be better renamed Parameters instead.

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.