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.

4

2 回答 2

0

在尝试了各种解析和循环方法但没有运气之后,不确定它是否是最好的方法,但我发现我可以抓住它并以这种方式分配变量

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

成功后我得到id = '208'id = '-1'失败

于 2016-11-16T16:26:00.647 回答
0

由于您的响应是 json 格式,您可以使用 JSON.parse() 函数。或者您可以将输出 json 分配给数组/变量并使用 for 循环您可以遍历它并访问它

于 2016-11-16T06:24:54.897 回答