Where to start with JSON? (Closed) - javascript

I'm trying to get started with JSON. I've set the link to the JSON.js file using a script link, and I've set my objects using JSON, but it returns no results at all when I try to refer to the object. The JSON doesn't seem to be working at all. If anyone could point me in the right direction it'd be appreciated. I've looked all over the internet and haven't found much to help me.
Thanks guys. The JSON website helped me figure it out

Get Firefox, get Firebug, learn to use it to see what javascript is being loaded, and where the errors are.
Oh, and post some code.

Take a look-see at this
http://json.org/
basically you need to understand that json is a way to stream javascript object literals and arrays from a server to the client (and vice-versa). Open up firebug/webkit and in the console try
var obj = JSON.parse('{"test": 1}')
and you will see that obj is an object literal with a test property.
edit -- note that the link I provided mentions that json is a "is a lightweight data-interchange format" -- so its does not need to be javascript specific. But I think in practice you will get the most mileage using json in conjunction with javascript.

Here's a couple of links that might help:
http://secretgeek.net/json_3mins.asp
http://www.hunlock.com/blogs/Mastering_JSON_(_JavaScript_Object_Notation_)

Related

Firebug binary variable

Hy,
I have a binary array that comes from deflating a string using this library.
I want to see the contents of the array in hex in firebug's console.
It's possible to do this? If it's possible, how can I do?
Of course, I tried console.log(array) in raw_deflating.js but it shows some garbage(of course, because it's binary)
I searched a lot on net, and surprisingly no one has asked this before.
Thank you,
I'll answer to my own question, if someone will have the same question:
Unfortunately, Firebug hasn't this feature. You can't see in debugger the hex value of a variable.
But, in my particular case, I was able to see the dec value of the variables directly from JavaScript, because the char array comes from String.fromCharCode(buff[j]);.
So, if you have a byte array, you can inspect the content using JS function String.charCodeAt()

How to find, where the Javascript keeps an Object I am interested in?

There is a website, which does POST, and I want to know, where parameters are stored. I need it to hack them, edit before posting. Scripts are huge and obfuscated, so I can't find the Objects I need just by reading the source code.
I've tried to serialize the window with JSON.prune from this answer. The keyword, which I use to find, where the string I need is stored, was found near 40 times in 28 megabytes of text. And it is not very readable even after I found substrings. So maybe it is not the way to go.
I need something which would tell me:
this substr has been detected in:
-- the String window.bla_bla_bla.deepobject.bla[5].blabla.msg_to_post
-- the String window.bla_bla_bla.deepobject.bla[3].and_here
-- the String window.and_even_here
-- etc.
First, find the function that send POST request.
Is request sent when you click button? visual event can help you find it.
Next, Read the function and overwrite it with your own.
If scripts are minified, use beautifier like this
Normally, with Chrome developer tool and visual event I got all thing want to know.

Flash Twitter API with JSON

I have read a lot about parsing JSON with Actionscript. Originally it was said to use this library. http://code.google.com/p/as3corelib/ but it seems Flash Player 11 has native support for it now.
My problem is that I cannot find examples or help that takes you from beginning to end of the process. Everything I have read seems to start in the middle. I have no real experience with JSON so this is a problem. I don't even know how to point ActionScript to the JSON file it needs to read.
I have a project with a tight deadline that requires me to read twitter through JSON. I need to get the three most recent tweets, along with the user who posted it, their twitter name and the time those tweets were posted.
The back end to this is already set up I believe by the development team here, therefor my JSON files or XML just needs to be pointed to and then I need to display the values in the interface text boxes I have already designed and created.
Any help will be greatly appreciated...I do know that there are a lot of threads on here I just do not understand them as they all have some understanding of it to begin with.
You need to:
Load the data, whatever it is.
Parse the data from a particular format.
For this you would normally:
Use URLLoader class to load any data. (Just go to the language reference and look into example of how to use this class).
Use whatever parser to parse the particular format that you need. http://help.adobe.com/en_US/FlashPlatform/beta/reference/actionscript/3/JSON.html this is the reference to JSON API, it also shows usage examples. I'm not aware of these API being in production version of the player, still there might be quite a bit of FP 10.X players out there, so I'd have a fallback JSON parser, but I would recommend using this library: http://www.blooddy.by/en/crypto/ over as3corelib because it is faster. The built-in API are no different from those you would find in browser, so if you look up JSON JavaScript entries, the use should be in general similar to Flash.
After you parse JSON format, you will end up with a number of objects of the following types: Object, Array, Boolean, Number, String. It has also literals to mean null and undefined. Basically, you will be working with native to Flash data structures, you only should take extra care because they will be dynamically constructed, meaning you may not make assumption about existence of parts of the data - you must always check the availability.
wvxvw's answer is good, but I think skips over a to be desired explanation of what JSON itself is. JSON is plain text, javascript object notation, when you read the text on screen it looks something like this
http://www.json.org/example.html
you can see a side by side JSON and XML (both plain text formats) essentially JSON is a bunch of name value pairs.
When you use JSON.parse("your JSON string goes here") it will do the conversions to AS3 "dynamic objects" which are just plain objects (whose properties can be assigned without previously being defined, hence dynamic). But to make a long story short, take the example you see in the link above, copy and paste the JSON as a string variable in AS3, use
var str:String = '{"glossary": {"title": "example glossary","GlossDiv": {"title": "S","GlossList": {"GlossEntry": {"ID": "SGML","SortAs": "SGML","GlossTerm": "Standard Generalized Markup Language","Acronym": "SGML","Abbrev": "ISO 8879:1986","GlossDef": {"para": "A meta-markup language, used to create markup languages such as DocBook.","GlossSeeAlso": ["GML", "XML"]},"GlossSee": "markup"}}}}}';
var test:Object = JSON.parse(str);
method on the string, store it in a variable and use the debugger to see what the resulting object is. As far as I know there's really nothing else to JSON it's simply this format for storing data (you can't use E4X on it since it's not XML based and because of that it's slightly more concise than XML, no closing tags, but in my opionion slightly less readable... but is valid javascript). For a nice break-down of the performance gains/losses between AMF, JSON and XML check out this page: http://www.jamesward.com/census2/ Though many times you don't have a choice with regard to the delivery message format or protocol being used if you're not building the service, it's good to understand what the performance costs of them are.

How to access a document.doc and .txt modify the content using javascript

Is it possible to access the .doc files and update in that document using javascript .
Thanks
I don't believe you can do this, for one .doc isn't stored in a format JavaScript can easily interpret...and I'm unaware of anyone ever taking the effort to port the .doc format to JavaScript. If it was possible, the library would need to edit it in memory and upload it again in some other format, base64 encoded perhaps?
In any case this is no small project, it's a huge effort and I've never seen anything close. That being said, there are alternatives depending on your exact needs, for example these guys do a browser implementation: http://www.textcontrol.com/en_US/products/dotnet/overview/
I'm not sure if there are others, and I haven't personally used theirs, but maybe that'll put you on the right track to finding the client solution you're after.
You used to be able to do this with ActiveX objects in IE. Probably still can. Code looked something like this:
var word = new ActiveXObject("Word.Application");
word.Visible = true;
// ...
See the reference for word's object model.

Converting XML-RPC to JSON in JavaScript

Can anyone recommend a lightweight JavaScript XML-RPC library?
After researching this a while ago, I couldn't find anything I was comfortable with, so I kinda ended up writing my own.
However, maybe that was stupid, as there must be something suitable out there!?
My own pseudo-library is mainly missing a way to turn an XML-RPC response into JSON - or rather, converting the respective responseXML to a JavaScript object (converting the data types as needed).
This isn't hard to do, but why reinvent the wheel...
Any help would be greatly appreciated!
I know this two libraries, that you can basically use to convert your XML-RPC responses to JSON:
XML to JSON Converter
xml2json.js
This seems to do what you (and I) want:
http://kuriositaet.de/javascript/jsxmlrpc.html
http://kuriositaet.de/javascript/xmlrpc.html
http://sourceforge.net/projects/jsxmlrpc/
Another small XML to JSON (and vice versa) JavaScript library is here -> http://code.google.com/p/x2js/
I could use this too. Generic XML to Json is rather unconvenient for XML-RPC.

Categories

Resources