Jump to content



Photo

Json ?


  • Please log in to reply
9 replies to this topic

#1 Original Poster

Original Poster

    Systems Developer

  • Tech Issues Solved: 1
  • Joined: 15-July 08
  • Location: my room
  • OS: windows 7/8, Kali, ubuntu, OSx 10.9
  • Phone: Android

Posted 22 December 2012 - 23:40

hi I have tried reading the documentation on json but its not getting me anywhere ... I could tell you exactly what json is and does ....

json is a language which belongs to the javascript family blah blah blah it can be used to communicate between different languages and platforms ect ect .... but the thing is I have no idea how this thing is working can someone give me links to json / php to java tutorials that they have found usful ? or give me some small little bits of code so i can see what the hell is going on ? or give me some indepth explination to what i can do with this ? I need to learn it apparently


#2 Max Norris

Max Norris

    Neowinian Senior

  • Tech Issues Solved: 20
  • Joined: 20-February 11
  • OS: Windows 7/8.1, BSD Unix, Arch Linux
  • Phone: HTC One (Home) Lumia 1020 (Work)

Posted 23 December 2012 - 00:00

or give me some indepth explination to what i can do with this ?


Familar with XML? Same kinda thing, just (in my opinion) better. It's just an easy standardized way for one program to talk to another.. regardless of who wrote it, if it properly parses JSON data, it'll get there unmangled. It's not a transport, just a way to ensure that program A can understand program B and vice versa. Some IDE's will have JSON parsers built in so you can view/serialize data a bit easier, there's some online too. Take your data, serialize it into JSON, and presto, you get something like below. The other program receives this then does it in reverse, and you get a "tree" which you should be able to easily visualize in your head with this example.

{
	 "firstName": "Max",
	 "address": {
		 "streetAddress": "123 Main St.",
		 "city": "Anytown",
		 "state": "US",
		 "postalCode": 12345
	 },
	 "phoneNumbers": [
		 "123-456-7890",
		 "123-555-1212"
	 ]
}


#3 +Karl L.

Karl L.

    xorangekiller

  • Tech Issues Solved: 15
  • Joined: 24-January 09
  • Location: Virginia, USA
  • OS: Debian Testing

Posted 23 December 2012 - 00:01

JSON is merely a data-interchange format for passing data between programs written using various languages/technologies. Since it is widely used on the Internet and PHP has a habit of including the kitchen sink, it also has JSON encode and decode functions built-in (since PHP 5.2.1). The json_decode page in the PHP manual has not only function documentation but also several examples. You might also take a look at this StackOverflow question about parsing JSON in PHP. It has most of the code for a complete parser.

#4 OP Original Poster

Original Poster

    Systems Developer

  • Tech Issues Solved: 1
  • Joined: 15-July 08
  • Location: my room
  • OS: windows 7/8, Kali, ubuntu, OSx 10.9
  • Phone: Android

Posted 23 December 2012 - 00:18

Familar with XML? Same kinda thing, just (in my opinion) better. It's just an easy standardized way for one program to talk to another.. regardless of who wrote it, if it properly parses JSON data, it'll get there unmangled. It's not a transport, just a way to ensure that program A can understand program B and vice versa. Some IDE's will have JSON parsers built in so you can view/serialize data a bit easier, there's some online too. Take your data, serialize it into JSON, and presto, you get something like below. The other program receives this then does it in reverse, and you get a "tree" which you should be able to easily visualize in your head with this example.

{
	 "firstName": "Max",
	 "address": {
		 "streetAddress": "123 Main St.",
		 "city": "Anytown",
		 "state": "US",
		 "postalCode": 12345
	 },
	 "phoneNumbers": [
		 "123-456-7890",
		 "123-555-1212"
	 ]
}


oh that seems a bit long winded :/ I got my program at the moment posting to a php script then catching the response via datainputstream ... is this fine? or do you think Json would be better ? for large bits of information I send as 1 string with specific parameters so my java program can handle and string manipulate its self... I Dont know what i was hoping for with json but to me it does not sound that useful sounds like there are many alternatives... :(

#5 kjordan2001

kjordan2001

    Mystery Solver

  • Tech Issues Solved: 1
  • Joined: 27-May 02

Posted 23 December 2012 - 00:44

oh that seems a bit long winded :/ I got my program at the moment posting to a php script then catching the response via datainputstream ... is this fine? or do you think Json would be better ? for large bits of information I send as 1 string with specific parameters so my java program can handle and string manipulate its self... I Dont know what i was hoping for with json but to me it does not sound that useful sounds like there are many alternatives... :(

JSON would be what's received by the InputStream. It's not a replacement for any data socket handling things, it is the data. If your data needs lots of key-value things like you're sending objects, maps, or arrays across, then JSON would be good for your uses. It's not good for just straight strings or for binary data.

#6 Andre S.

Andre S.

    Asik

  • Tech Issues Solved: 13
  • Joined: 26-October 05

Posted 25 December 2012 - 06:49

As its name implies, JSON is a notation, a standardized way of writing a set of named values in a text file. It doesn't do anything, it's just data written following some rules.

#7 Brony

Brony

    Brony power!

  • Joined: 29-October 01

Posted 26 December 2012 - 23:54

be careful with json because literal with " symbol could fail.

For example
name=it is a test "test"
sometimes is converted to json to
"name":"it is a test "test""
and it is incorrect.

#8 The_Decryptor

The_Decryptor

    STEAL THE DECLARATION OF INDEPENDENCE

  • Tech Issues Solved: 5
  • Joined: 28-September 02
  • Location: Sol System
  • OS: iSymbian 9.2 SP24.8 Mars Bar

Posted 27 December 2012 - 00:28

To avoid stuff like that, you'll want to ensure that you're using a proper JSON encoder/decoder. JSON isn't actually JavaScript (It just shares the object notation, hence the name) and there's a bunch of subtle differences that can cause things to break if the parser isn't smart/good enough (Which is also another reason you never parse JSON using eval(), and be very very careful with "JSONP", grab it via XHR instead, etc.)

#9 Riva

Riva

    Neowinian Senior

  • Tech Issues Solved: 1
  • Joined: 11-February 07

Posted 27 December 2012 - 01:10

Just to add a bit more to what the guys already said, JSON has replaced SOAP in many cases since its lighter than SOAP XML (in length) and it is something that JavaScript can parse natively into objects instead of you having to write code to create objects out of your data. In the ASP.NET world, this has been applied heavily via WCF services based on HTTP/JSON and either JQuery, ASP.NET AJAX or just plain JavaScript for client-side data binding.
http://www.json.org/js.html

#10 Litespeed

Litespeed

    Neowinian

  • Joined: 27-May 04
  • Location: New Zealand

Posted 27 December 2012 - 01:27

JSON = JavaScript Object Notation. The name kinda explains what it is. It's simply a way of notating javascript objects so you can pass them around in a standardised, lightweight way.

BTW, if you're using Chrome, install the JSONView extension which will automatically format JSON responses into a nice readable display.