1

I got a response from a rest call and such that (Ref ? Ref : "UNKNOWN"),source.datetime.replace(/T/, ' ').replace(/Z/, '') and source.status_code have the respective response values.This is in one if loop and I consoled this in a variable and it displays as

var data = (Ref ?Ref : "UNKNOWN") +  source.datetime.replace(/T/, ' ').replace(/Z/, '') +source.status_code ;

In logs i get as
dataaaaa 50073151 2017-02-24 16:14:41.203200 OK
dataaaaa 50005230 2017-02-24 15:40:46.190200 OK
dataaaaa 50073481 2017-02-24 09:16:14.885200 OK

Now I have a array as

var content = '{Ref":"","createdTime":"","responseCode":""}'

So I want to store above response as json object as

{{Ref":"50073151","createdTime":"2017-02-24 16:14:41.203","responseCode":"200 OK"},{Ref":
"50005230","createdTime":"2017-02-24 15:40:46.190","responseCode":"200 OK"},{Ref":
"50073481","createdTime":"2017-02-24 09:16:14.885","responseCode":"200 OK"}}

How can we get this..can some help me in this..Thanks!

2
  • Since you have not accepted the answer but just upvoted, did it solve your problem? Commented Feb 27, 2017 at 11:35
  • @SharjeelAhmed Ive added the comment.Not solved completely Commented Feb 27, 2017 at 11:40

1 Answer 1

1

I suggest you add a space here

var data = (Ref ?Ref : "UNKNOWN") +  source.datetime.replace(/T/, '').replace(/Z/, '') +' '+source.status_code ;

then split the data into an array

var JSONArr=[];

var arr = data.split(' ');
var obj={"Ref":arr[0],"createdTime":arr[1],"responseCode":arr[2]};
JSONArr.push(obj);

You need to loop the last 3 lines. Also since you have space in your data itself like date, you may want to split it in some other character, but you get the point.

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

9 Comments

...Thanks for ur help..It worked partially.The way json is getting consoled is {Ref":"50073151","createdTime":"2017-02-24 16:14:41.203","responseCode":"200 OK"},{Ref": "50005230","createdTime":"2017-02-24 15:40:46.190","responseCode":"200 OK"} only one json object at a time.On what condition can we add the loop so to get as one array..Am bit confused.Any help would be very useful to me @sharjeel
JSONArr is the array with all the elements. You need to put the loop only in the last 3 lines. Please paste your code in jsfiddle, save it and send me the link
ok..no problem if u cant join..I'll send to the fiddle hope it would understand
sorry was out, can join now
can u join now?
|

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.