我有一些数据是从数据馈送中作为文本检索的。例如,收到的数据如下所示:从json.dumps的字符串数据中删除双引号
1105488000000, 34.1300, 34.5750, 32.0700, 32.2800\r\n
1105574400000, 32.6750, 32.9500, 31.6500, 32.7300\r\n
1105660800000, 36.8250, 37.2100, 34.8650, 34.9000\r\n
等
(这是库存数据,其中第一列是时间戳,下一列是开放的,高,低,和收盘价为时间段)
我打算将它转换成JSON如以下几点:
[
[1105488000000, 34.1300, 34.5750, 32.0700, 32.2800],
[1105574400000, 32.6750, 32.9500, 31.6500, 32.7300],
[1105660800000, 36.8250, 37.2100, 34.8650, 34.9000],
...
的代码,我使用的是:
lines = data.split("\r\n");
output = []
for line in lines:
currentLine = line.split(",")
currentLine = [currentLine[0] , currentLine[1] , currentLine[2], currentLine[3], currentLine[4]]
output.append(currentLine)
jsonOutput = json.dumps(output)
然而,当我这样做,我发现这些值是:
[
["1105488000000", "34.1300", "34.5750", "32.0700", "32.2800"],
["1105574400000", "32.6750", "32.9500", "31.6500", "32.7300"],
["1105660800000", "36.8250", "37.2100", "34.8650", "34.9000"],
反正对我来说,得到的输出没有双引号?
这是因为您将字符串插入到数组中而不是插入数字。 – 2012-03-06 02:28:53