Javascript and C# COM interaction - javascript

I am using C# COM Interop techniques to interact with some device from website using ActiveX. Right now I can call C# codes from javascript and pass only string values. But I intend to pass javascript structure into C# method and the reverse. How can I do that.
Right now as an alternative I pass JSON formatted string from C# code and generate javascript object runtime using eval. But I want more control on that.
Thanks
Maksud

I ended up using NewtonSoft's JSON Library as I could not find native solution.

Related

Convert Pickle Object into JS-readable Code?

I'm pretty new to the Pickle Library and JS. I am writing code in JS to interact with a Python server; when I make a POST to the Python server, I am returned a pickled float. I want to convert the float into a JS-readable object.
The server returns something like pickle.dumps(3.14159,0). When I print this value in Python, I get b'F3.14159\n.' However, the library I'm working with, JPickle, cannot interpret the 'b' in the return (or at least, that's what I'm guessing...when I try to unpickle my response using console.log(jpickle.loads(response)), I get a "unhandled opcode" error). Separate from the POST request, jpickle.loads('F3.14159\n.') gives me 3.14159, but jpickle.loads(b'F3.14159\n.') fails to compile. I'm not sure how to change the response I get from the POST because it is unreadable in JS, so I'm unsure how to go about solving this problem.
I'm open to any solutions that don't involve changing the server-side code (I don't have control over it), including using another library. I've tried JsonPickle with no luck.
Use just JSON, no pickle library required; Python comes with the json module and browser JS can, out of the box, parse json into values.
Serialize your data via something like json.dump and use JSON.parse in the browser to deserialize it.
A little late, but the answers in attached might help:: the code allows Javascript on a browser to traverse and decode compressed pickled objects coming from Python via Ajax.
Is there an already published Javascript solution to traverse Python pickled objects without using Node.js
Make sure that the mime type is allowing you to pass binary numbers.

Can Kotlin or Swift parse JSON just like Javascript?

If I'm using javascript (or TypeScript), I can do following (just idea);
object = JSON.parse(jsonString)
And I can just use it like this,
alert(object.property);
Super Simple.
If I'm using Java, I need to create classes and parse it to use it. I understand.
How about Kotlin and Swift. They have optional types, so why single line, Javascript-like simple parsing doesn't exist for them, or does it? (Without even data class or going through JSON's properties)
If you look up what JSON stands for it's no wonder why JavaScript has "native support" for it: JavaScript Object Notation
In Kotlin you'll need to use libraries for parsing JSON, I'd recommend Jackson for that, a library widely used with Java already.

Processing.js a way to create JSON

Is there some kind of constructor or some way to create Json object in processing.js? I know that in the Processing library have JSONObject but in the processing.js there is nothing like that everything that I found for processing.js is how to load JSON but I need some kind of way to create it. If there is way can someone show me how to do it.
JSONObject is used by Java (or Processing in Java mode) to create JSON Strings that can be used by JavaScript.
Processing.js is already JavaScript, so you don't need to go through all that trouble.
If you have an object in JavaScript (and Processing.js is already JavaScript), then you can just use the JSON.stringify() function that's built in to JavaScript (and Processing.js).
But again, you might not even need to do this. Processing.js is already JavaScript, so you can probably just use the objects directly in JavaScript code without converting them to JSON first.

Best way to convert JSON data to an object in JavaScript?

I am currently using eval in JavaScript to convert JSON data returned from the server into an object.
eval ("myObject="+data);
I've been told that eval is 'evil' and can open up big security problems.
I'm wondering - is using eval to convert JSON data to an object the accepted practice? Or is there a better way?
The reason eval is considered a bad practice is that user can evaluate anything that is sent from the server. This means if you have comments forum and the user submits some JavaScript code for the comments and you eval on the client side then your website can easily be hijacked.
I like the JQuery-Json plug-in. You can check it out using the following link:
link text

Is there a way to call server side Groovy object method from client side JavaScript code via AJAX?

There is DWR which satisfies my needs in Java. I'm interested if there is any Groovier way to do the same thing - with convention over configuration, dynamic method invokation, etc.
I don't think there is such framework at the moment. In the mean time, you may try using Groovy objects with DWR.
Or if you're going to use Grails, you may have a look at Grails DWR plugin:
http://grails.org/DWR+Plugin
And this one is an unofficial update for DWR 3:
http://www.nabble.com/Updated-DWR-Plugin-for-DWR-3-td21421849.html
I would recommend looking into Grails. The content negotiation feature can be used to return Groovy objects from grails controllers in different formats (xml, json, etc.) and you can consume the JSON on the client side. It literally just takes a few lines of code from a grails controller to return HTML, JSON and XML representations of your objects.

Categories