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
我正在使用seriate调用存储过程来注册用户,并在创建用户时使用输出JSON,并且第一个值{“”:208}是生成的userId
{"sets":{"sp_CreateNewUser":[[[{"":208}],[{"":1664}],[{"":1665}],[{"":1666}],[{"":1667}],[{"":1668}],[{"":1669}],[{"":1670}],[{"":1671}],[{"":210}],[{"":212}]],0]},"transaction":{}}
{ “套”:{ “sp_CreateNewUser”:[[[{ “”:208}],[{ “”:1664}],[{ “”:1665}],[{ “”:1666}],[{ “”:1667}],[{ “”:1668}],[{ “”:1669}],[{ “”:1670}],[{ “”:1671}],[{ “”:210} ],[{ “”:212}]],0]}, “交易”:{}}
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.
如何解析此输出以获取userId并将其传递给下一个函数,或者如果输出-1则执行另一个函数。
2 个解决方案
#1
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
由于您的响应采用json格式,因此您可以使用JSON.parse()函数。或者您可以将输出json分配给数组/变量,并使用for循环可以遍历它并访问它
#2
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
成功后,我在失败时得到id ='208'或id =' - 1'
#1
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
由于您的响应采用json格式,因此您可以使用JSON.parse()函数。或者您可以将输出json分配给数组/变量,并使用for循环可以遍历它并访问它
#2
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
成功后,我在失败时得到id ='208'或id =' - 1'