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.
Related
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.
In javascript, I want to use JSON.stringify. But some (older) browsers do not recognize JSON as a defined object. Is there a javascript file that I can include that defines JSON, and all it's awesome functionality, for browsers that do not natively support JSON?
I should note that I'm referring to a specifically defined JSON object, rather than the more general concept of javascript object notation.
Douglas Crockford (the inventor of JSON) provides json2.js, an efficient JSON "parser" that doesn't actually parse JSON; it uses regular expressions to sanitise JSON before passing it to eval, and falls back on native JSON support if the browser has it.
He also provides a more conventional recursive-descent parser and a state-machine-based parser in the same repo.
What are the JavaScript functions or libraries that are equivalent to Ruby's pack and unpack functions for the Array class? I'm particularly interested in converting hex strings to strings.
irb(main):022:0> ["446f67"].pack("H*")
=> "Dog"
I'm not a JavaScript programmer and would rather not roll my own converter if libraries are available.
I don't think JavaScript has a function that does quite the same thing; pack seems to be a Ruby specific. If you're using pack to turn an object into a string, which can be sent over a network, you could use JSON instead. The Prototype library provides methods for turning objects into JSON-encoded strings. There are also Ruby libraries for working with JSON (encoding and decoding) such as:
http://flori.github.com/json/
answered here: pack / unpack functions for node.js
I'm using python-spidermonkey to run JavaScript code.
In order to pass objects (instead of just strings) to Python, I'm thinking of returning a JSON string.
This seems like a common issue, so I wonder whether there are any facilities for this built into either Spidermonkey or python-spidermonkey.
(I do know about uneval but that is not meant to be used for JSON serialization - and I'd rather avoid injecting a block of JavaScript to do this.)
I would use JSON.stringify. It's part of the ECMAScript 5 standard, and it's implemented in the current version of spidermonkey. I don't know if it's in the version used by python-spidermonkey, but if it isn't, you can get a JavaScript implementation from http://www.json.org/js.html.
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.