Hi Buran and Snippsat,
Thanks for your advises and quick reply. Actually, I am using json module to working with json. I used json.dumps but it didn't work, the non-ascii isn't displayed correctly.
This is my previous code. I realized the json I got from Jira Rest API is correct but json.dumps() makes it incorrect.
Tien
Thanks for your advises and quick reply. Actually, I am using json module to working with json. I used json.dumps but it didn't work, the non-ascii isn't displayed correctly.
This is my previous code. I realized the json I got from Jira Rest API is correct but json.dumps() makes it incorrect.
def getTicketFieldsAndComments(TicketKeys, filepath): totalTickets = len(TicketKeys) f = Util.createFile(filepath) f.write('{ "total":' + str(totalTickets) + ', ') f.write('"smallest":"' + TicketKeys[0] + '", ') f.write('"largest":"' + TicketKeys[totalTickets-1] + '", ') f.write('"issues":[') lastIssue = totalTickets - 1 for i, ticketNumber in enumerate(TicketKeys): issue = json.loads(subprocess.check_output('java -jar OAuthTutorialClient-1.0.jar request "https://impulsepoint.atlassian.net/rest/api/latest/issue/' + ticketNumber + '"' , shell=True, encoding="437")) if i == lastIssue: f.write(json.dumps(issue)) else: f.write(json.dumps(issue) + ',') f.write(']}') f.close()Cnull, I also tried to use ensure_ascii=False and it didn't work either
def getTicketFieldsAndComments(TicketKeys, filepath): totalTickets = len(TicketKeys) f = Util.createFile(filepath) f.write('{ "total":' + str(totalTickets) + ', ') f.write('"smallest":"' + TicketKeys[0] + '", ') f.write('"largest":"' + TicketKeys[totalTickets-1] + '", ') f.write('"issues":[') lastIssue = totalTickets - 1 for i, ticketNumber in enumerate(TicketKeys): issue = json.loads(subprocess.check_output('java -jar OAuthTutorialClient-1.0.jar request "https://impulsepoint.atlassian.net/rest/api/latest/issue/' + ticketNumber + '"' , shell=True, encoding="437")) if i == lastIssue: json_string = json.dumps(issue, ensure_ascii=False).encode('utf-8') f.write(json_string.decode()) # f.write(json.dumps(issue)) else: json_string = json.dumps(issue, ensure_ascii=False).encode('utf-8') f.write(json_string.decode()) f.write(",") #f.write(json.dumps(issue) + ',') f.write(']}') f.close()And this is the location in tmp.json which threw the exception and error
"body": "Ashley Tarloski <[email protected]> commented:\n\nHi Dan,\n\nIxE2\u20acx99m on the phone with support now.\n\nThanks,\nAshley", "updated": "2017-08-03T13:58:41.682-0400"The correct text should be
Ashley Tarloski <[email protected]> commented:\n\nHi Dan,\n\nI'm on the phone with support now.\n\nThanks,\nAshleyRegards,
Tien