0

I am trying to return two json sets from java which each contain key/value pairs. I can get the data to return as expected but once I have the data I can not access it properly. Here is what my data coming from the java looks like

{"RESULTS":
    {"MAP_1":
       [
         {"value":"1","display":"output text","type":"type a"},
         {"value":"2","display":"more output text","type":"type a"}
        ],
      "MAP_2":
        [
         {"value":"1","display":"output text","type":"type b"},
         {"value":"2","display":"more output text","type":"type b"}
         ]
     }
}

I have tried using $.map and $.each but I can not seem to drill into the data any help would be greatly appeciated.

Here is my latest attempt:

$.ajax({
    url: url,
    dataType: "text",
    data: {
         searchString: request.term
    },
    success: function( data ) {
        response( $.map( data.MAP_1, function( item ) {
            label: item.value + ", " + item.type
                value: item.display
        }));
    }
});

Thanks in advance!

1 Answer 1

1

The format of the data returned by java is text, not json. So you should specify the dataType as json. In addition the following code are not right, I think.

data.MAP_1

should be

data.RESULTS.MAP_1
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much!!! I have been beating my head over this for the past hour or so.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.