Skip to content

Commit

Permalink
fix problem when text attributes include %
Browse files Browse the repository at this point in the history
Sometimes text attributes include % symbol. It was treated as correct or
incorrect format specification in "row_json_str % (NL, ....)" python
line. The code was changed to avoid this problem.
  • Loading branch information
azhigimont committed Mar 16, 2015
1 parent 97bd8a7 commit 0c7ced7
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions JSONUtil.py
Expand Up @@ -364,11 +364,9 @@ def ConvertFC2JSON(fc, ftmp, pjson = False) :
attributes_str = unicode(json.dumps(attributes_json, indent = (4 if pjson else None)))
if feature_type :
geometry_str = unicode(row[len(row) - 1]) if pjson != True else unicode(json.dumps(json.loads(row[len(row) - 1]), indent=4))
row_json_str = u'{{%s"attributes": {0},%s"geometry": {1}%s}}'.format(attributes_str, geometry_str)
row_json_str = row_json_str % (NL, NL, NL)
row_json_str = u'{{{2}"attributes": {0},{3}"geometry": {1}{4}}}'.format(attributes_str, geometry_str, NL, NL, NL)
else:
row_json_str = u'{{%s"attributes": {0}%s}}'.format(attributes_str)
row_json_str = row_json_str % (NL, NL)
row_json_str = u'{{{1}"attributes": {0}{2}}}'.format(attributes_str, NL, NL)

ftmp.write(row_json_str)

Expand Down Expand Up @@ -418,11 +416,9 @@ def ConvertFC2JSONUnenclosed(fc, ftmp, pjson = False) :
attributes_str = unicode(json.dumps(attributes_json, indent = (4 if pjson else None)))
if feature_type :
geometry_str = unicode(row[len(row) - 1]) if pjson != True else unicode(json.dumps(json.loads(row[len(row) - 1]), indent=4))
row_json_str = u'{{%s"attributes": {0},%s"geometry": {1}%s}}%s'.format(attributes_str, geometry_str)
row_json_str = row_json_str % (NL, NL, NL, NL)
row_json_str = u'{{{2}"attributes": {0},{3}"geometry": {1}{4}}}{5}'.format(attributes_str, geometry_str, NL, NL, NL, NL)
else:
row_json_str = u'{{%s"attributes": {0}%s}}%s'.format(attributes_str)
row_json_str = row_json_str % (NL, NL, NL)
row_json_str = u'{{{1}"attributes": {0}{2}}}{3}'.format(attributes_str, NL, NL, NL)

ftmp.write(row_json_str)

Expand Down

0 comments on commit 0c7ced7

Please sign in to comment.