0

I'm calling a stored procedure using seriate to register users and the output JSON like this when the user is created and the first value {"":208} is the generated userId

{"sets":{"sp_CreateNewUser":[[[{"":208}],[{"":1664}],[{"":1665}],[{"":1666}],[{"":1667}],[{"":1668}],[{"":1669}],[{"":1670}],[{"":1671}],[{"":210}],[{"":212}]],0]},"transaction":{}}

and it looks like this when it fails

{"sets":{"sp_CreateNewUser":[[[{"":-1}]],0]},"transaction":{}}

How can I parse this output so to grab the userId and pass it to the next function or if the out put -1 to do another function.

user2374165
  • 13
  • 1
  • 6

2 Answers2

0

As your response is in json format you can use JSON.parse() function. or you can assign output json to array/variable and using for loop you can traverse through it and access it

AJS
  • 953
  • 7
  • 21
0

After trying all sort of parsing and looping methods with no luck, not sure if its the best way to do, but I found I can grab it and assign variable this way

var id = user.sets.sp_CreateNewUser['0']['0']['0'][''];

after success i get id = '208' or id = '-1' on failure

user2374165
  • 13
  • 1
  • 6