I'm trying to iterate through the list of JSON, it just iterate only the first row How could I able to loop through all the rows inside the list
This is my payload in browser
[{AuditorId: 10, Agents: Joshi", Supervisor: Prabhu", TicketId: "R6726587",…},…]
0: {AuditorId: 10, Agents: Joshi", Supervisor: Prabhu", TicketId: "R6726587",…}
1: {AuditorId: 10, Agents: Joshi", Supervisor: Prabhu", TicketId: "R6726587",…}
2: {AuditorId: 10, Agents: Joshi", Supervisor: Prabhu", TicketId: "R6726587",…}
3: {AuditorId: 10, Agents: Joshi", Supervisor: Prabhu", TicketId: "R6726587",…}
4: {AuditorId: 10, Agents: Joshi", Supervisor: Prabhu", TicketId: "R6726587",…}
here, what I tried
@api_view(['POST'])
def UserResponse(request):
if request.method == 'POST':
for ran in request.data:
auditorid =ran.get('AuditorId')
ticketid = ran.get('TicketId')
qid = ran.get('QId')
answer = ran.get('Answer')
sid = ran.get('SID')
TicketType = ran.get('TicketType')
TypeSelected = ran.get('TypeSelected')
agents = ran.get('Agents')
supervisor = ran.get('Supervisor')
Comments = ran.get('Comments')
action = ran.get('Action')
subfunction = ran.get('AuditSubFunction')
region = ran.get('AuditRegion')
Qstans = str(qid)+'|'+ answer+'&&'
cursor = connection.cursor()
cursor.execute('EXEC [dbo].[sp_SaveAuditResponse] @auditorid=%s,@agents=%s,@supervisor=%s,@ticketid=%s,@Qstans=%s,@sid=%s,@TicketType=%s,@TypeSelected=%s, @Comments =%s, @action=%s, @subfunction=%s, @region=%s',
(auditorid,agents,supervisor,ticketid, Qstans,sid, TicketType, TypeSelected, Comments, action, subfunction,region))
result_st = cursor.fetchall()
for row in result_st:
return Response({0:row[0]})