0

Below is the response I am getting from HttpRequest. I want to return this response in JSON to Ajax request from spring controller.

({
   'KUI': {
       code: '.KUI',
       indexDetailEnable: true,
       price: '20,650.21',
       netChange: '-13.01',
       percentChange: '-0.06%',
       tradeDate: '17/04/03',
       tradeTime: '16:50',
       chartDate: '17/04/03',
       chartTime: '16:50'
    },

   'KUI': {
       code: '.NHK',
       indexDetailEnable: true,
       price: '--',
       netChange: '--',
       percentChange: '--%',
       tradeDate: '--/--/--',
       tradeTime: '--:--',
       chartDate: '17/04/03',
       chartTime: '17:15'
    },

    __end__: null
});
6
  • This is already in JSON except the brackets. Commented Apr 4, 2017 at 7:44
  • @CicilThomas I tried to print using jsonprettyprint but it printing null. { "abc": "abc" } I think this is the json format. Commented Apr 4, 2017 at 7:47
  • @CicilThomas I have removed ( ) and semicolon before printing. Commented Apr 4, 2017 at 7:49
  • What exactly are you trying to achieve? Commented Apr 4, 2017 at 7:55
  • 1
    In JSON a name/value pair consists of a field name (in double quotes), followed by a colon, followed by a value( via w3School). The keys of above response are not enclosed in " ". So how come above response is already in JSON? May be I am missing something. Commented Apr 4, 2017 at 8:02

1 Answer 1

1

you could use new JSONObject(yourResponse) or new JSONArray(youResponse) from org.json

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

Comments

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.