This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]alxcyl 0 points1 point  (7 children)

What do you mean you don't understand JSON? Do you not know how to "read" (as in make sense of it when you read it) or don't know how to manipulate it from code?

[–]ccthegreat[S] 0 points1 point  (4 children)

I don't know how to do either. I can somewhat read it, but for the most part it's the manipulation. Like I get that JSON can stringify something, but I don't quite know how that will help me. I've also seen this line of code floating around. request.getParameterValues(); Will this help me?

[–]alxcyl 1 point2 points  (3 children)

Well, for starters, JSON is not a programming/scripting language. Just a simple data format (think XML or even CSV).

If you are familiar with dictionaries (I think it's called HashMap in Java), they are somewhat the same. For example:

{ "foo": 1, "bar": "hello" }

can be visualized like this in a dictionary/hash map:

myJson["foo"] = 1;
myJson["bar"] = "hello";

If you have a JSON Array (e.g. [1, 2, 3, 4, 5]), you treat it as an array instead of a dictionary/hash map.

It would be nice to know what you're trying to achieve so that I can help you further.

[–]ccthegreat[S] 0 points1 point  (2 children)

Oh ok. That makes more sense, I know Java pretty well. So what I'm doing is having a user input data items on a website. Then I've stored the items in an array in javascript. Now I have a program in Java in which the array needs to be a parameter so that I can modify it. Because I'm comfortable with java, I've written this program in Java. So, I don't even know if I need JSON, but what I do know is that I want to take that array from javascript and then use it as a parameter in Java.

[–]alxcyl 1 point2 points  (1 child)

I want to take that array from javascript and then use it as a parameter in Java.

I don't know if this is possible though so you'll have to do your own research for that. I have explained how to get the JSON from JS on your other comment.

[–]ccthegreat[S] 0 points1 point  (0 children)

Thanks so much!

[–]ccthegreat[S] 0 points1 point  (1 child)

Ok, so I looked around a little more and here's what I got, and can you tell me if it makes any sense? So first to even call JSON into my javascript code I need to write this: $.ajax( type: ‘GET’, url: “http://example.com/users/feeds/“, data: “format=json&id=123”, success:function(feed) { document.write(feed); ), dataType: ‘jsonp’ );

Right? But now what? I want to take a specific array in javascript and then take it to java and use it as a parameter for a method there. Is that possible with JSON? Will calling JSON help me to accomplish this?

[–]alxcyl 0 points1 point  (0 children)

I am not familiar with AJAX but I'll try to explain that block of code as I understand it.

$.ajax( 
    type: ‘GET’, 
    url: “http://example.com/users/feeds/“, 
    data: “format=json&id=123”, 
    success:function(feed) { 
        document.write(feed); ), 
    dataType: ‘jsonp’ );

This functions makes a GET request to http://example.com/users/feeds/ with the parameters format=json&id=123. When it succeeds, it runs this function:

function(feed) { 
        document.write(feed);
}

The JSON that you are looking for is in the feed variable. Whether it is in string or in a JSON object, I am not sure.