0

I have following on click event :

private void button1_Click(object sender, EventArgs e)
{
    string usrname = textBox1.Text;
    string pass = textBox2.Text;
    Service1 ser = new Service1();
    string jay = ser.UsernamePass(usrname);

    dynamic string_json = Newtonsoft.Json.JsonConvert.DeserializeObject(jay);

    var password = string_json.login.Password.Value;

    if (pass == password)
    {
        h.Show();
    }
    MessageBox.Show("Wrong Password");
}

jay has Following value :

"{\"login\":[{\"Password\":\"admin123\"}]}"

string_json has following value :

{
    "login": [
    {
        "Password": "admin123"
    }]
}

At following line : var password = string_json.login.Password.Value;

It throws me following exception :

"'Newtonsoft.Json.Linq.JArray' does not contain a definition for 'Password'"

Can anyone help me with it that how i access data? Even it would be useful if you tell me another way to access data.

1 Answer 1

1

As I can see, login is array, so try:

var password = string_json.login[0].Password.Value;
Sign up to request clarification or add additional context in comments.

5 Comments

And if i want to count the entries in login then how would i do it?
Try property Count: james.newtonking.com
Can u give a example same way u gave above? plz
can u state me an example plz? @Elvedin Hamzagic
Do you want to get the Count or to enumerate through JSON? It you want count type string_json.login.Count for array, or string_json.login[0].Count for object inside array.

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.