json - Python: Why is every character of string on newline -
i have been trying prepare problem cannot. have next code:
import json def jsonblock(filename): my_array = [] open(filename) f: line in f: my_array.append(line) p = " ".join(str(x) x in my_array) homecoming p; in jsonblock('p5.json'): print(i)
and p5.json
{ "signalpassed" : true, "location" : { "longitude" : 113.3910083760899, "latitude" : 22.57224988908558 }, "phoneosversion" : "7.0.3", "signalstddev" : 4.139107, "phonemodel" : "ipad", }
i want normal output in str format when it, next output:
" 7 . 0 . 3 " , " s g n l s t d d e v " : 4 . 1 3 9 1 0 7 , }
where problem? how can prepare this?
your function jsonblock
returns string, result of ''.join(...)
. iterating on string produces individual characters, print out 1 1 in loop @ end.
to "solve" immediate problem, print jsonblock('p5.json')
instead of using loop.
however, want parse json correctly. in case, utilize json
library imported @ top.
filename = 'p5.json' open(filename, 'rb') f: info = json.load(filename) print info # info dictionary in case
python json
No comments:
Post a Comment