2012-07-30 276 views
0

比方說,我有一個包含字符串:如何從json字符串獲取值?

{"ticker":{"high":8.976,"low":8.843,"avg":8.9095,"vol":2096.78,"last":8.845,"buy":8.946,"sell":8.843,"server_time":1343686701}} 

我怎麼會拿號碼,把它們放在一個單獨的變量?

例如:

int high = 8.976 
int low = 8.843 
/* and so on */ 
+5

那麼一開始,不要使用int來存儲8.976 – mathematician1975 2012-07-30 22:24:44

+0

@ mathematician1975 - 他可能因1000第一 – Hogan 2012-07-30 22:25:37

+1

乘它,我會使用長一倍? – 2012-07-30 22:25:50

回答

3

很多方法。

「sscanf」是一種選擇。

標準字符串函數「strstr()」,「atof()」等是另一個。

我建議找一個好的JSON解析庫。例如:

+0

你是一個超級幫助,因爲你可以看到我對C非常陌生(並且一般編程) – 2012-07-30 22:39:15