【发布时间】:2012-03-06 02:06:47
【问题描述】:
我有一些从数据馈送中以文本形式检索的数据。例如,我收到如下数据:
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"],
无论如何我可以得到不带双引号的输出吗?
【问题讨论】:
-
这是因为您将字符串插入到数组中,而不是插入数字。