Skip to content

Commit

Permalink
修复不可见字符导致的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
debuggerx01 committed Jul 28, 2020
1 parent be0789b commit 3897c51
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 3 additions & 2 deletions formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ def update_list(json_str):
def json_format():
# 从文本编辑框获取json字符串
json_str = ui.te_json.toPlainText()
if is_json(json_str.strip()):
json_str = rm_invisible(json_str.strip())
if is_json(json_str):
# 将格式化后的json字符串覆盖到文本编辑框中
ui.te_json.setText(jformat(json_str.replace('\n', '')))

Expand Down Expand Up @@ -212,7 +213,7 @@ def generate_bean():
QMessageBox().information(msg_box_ui, "警告", "发生错误", QMessageBox.Ok)
return
if res != '':
ui.te_json.setText(res)
ui.te_json.setText(rm_invisible(res.strip()))


def str_to_camel_case(text):
Expand Down
11 changes: 9 additions & 2 deletions tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,24 @@
# @Author : DebuggerX

import json

from string import printable

from PyQt5.QtWidgets import QLabel, QComboBox, QMessageBox

from template_code import get_top_code_dict, get_list_code_loop

msg_box_ui = None


def rm_invisible(string):
return ''.join(char for char in string if char in printable)


# 验证json字符串是否合法
def is_json(myjson):
def is_json(my_json):
try:
j = json.loads(myjson)
j = json.loads(my_json)
except ValueError:
return False
if type(j) in (list, dict):
Expand Down

0 comments on commit 3897c51

Please sign in to comment.