0

I have following javascript function in my HTML document:

function jsFunction(string, jsonArray, string) { ... }

An example of jsonArray would be following:

[
{"name":"foo", "value":"21980"},
{"name":"bar", "value":"100"},
{"name":"foo", "value":"27492328"},
{"name":"bar", "value":"WEB21980001831"}
]

I followed the instructions from the post "Creating an JSON array in C#" in order to create a JSON Array object in C#.

From my Windows Form I should be able to call the JavaScript function like this:

 Object[] jsParams = new Object[3];
 jsParams[0] = (Object)"test";
 jsParams[1] = new
 {
     items = new[] {
         new {name = "foo" , value = "21980"}, 
         new {name = "bar" , value = "100"}, 
         new {name = "foo" , value = "27492328"}, 
         new {name = "bar" , value = "WEB21980001831"}
     }
 };
 jsParams[2] = (Object)"test";

 this.webBrowserCtl.Document.InvokeScript("jsFunction", jsParams);

However, it doesn't work. Did I forget something?

1 Answer 1

2

jsFunction is 3 parameter.

function jsFunction(string, jsonArray, string) { ... }

you send 4 argument.

 jsParams[0] = (Object)"test";
 jsParams[1] = new
 {
    items = new[] {
        new {name = "foo" , value = "21980"}, 
        new {name = "bar" , value = "100"}, 
        new {name = "foo" , value = "27492328"}, 
        new {name = "bar" , value = "WEB21980001831"}
    }
 };
 jsParams[2] = (Object)"content";
 jsParams[3] = (Object)"test";

Delete this line.

 //jsParams[3] = (Object)"test";

Parse jsonArray and use in jsFunction.

var data = JSON.parse(jsonArray ); 
Sign up to request clarification or add additional context in comments.

11 Comments

That's correct but that was a mistake by myself where I tested something else. It still doesn't work.
parse jsonArray and use in jsFunction. var data = JSON.parse(jsonArray );
Which assembly do I have to use for JSON.parse? Install-Package Newtonsoft.Json -Version 10.0.3?
in HMTL document. function jsFunction(string, jsonArray, string) { var data = JSON.parse(jsonArray ); ....... }
Yes but I cant find the JSON namespace
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.