2013-10-18 246 views
0

嗨我將JSON數據轉換爲字符串。請在下面找到JSON數據。我面臨的問題是系統無法將NULL值轉換爲字符串。因此,我收到以下錯誤:無法零轉換成字符串(類型錯誤)將JSON數據轉換爲字符串

JSON數據:

{"success":true,"message":null,"data":null} 

代碼中使用:

c = Curl::Easy.new(Configuration.fetch("<URL where we can find the above JSON DATA and nothing else>")) 
# c.follow_location = true 
# c.http_auth_types = :basic 
# c.username = Configuration.fetch('auth_user', false) 
# c.password = Configuration.fetch('auth_pass', false) 
# c.headers["User-Agent"] = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17' 
# c.perform 
    result=JSON.parse(c) 
    puts result["Success"] 

請幫助。

+0

向我們展示您當前正在產生錯誤的嘗試。 – meagar

+0

我編輯了這個問題。希望你現在可以看到代碼。 – san6086

回答

1

嘗試

puts result["success"] 

你有一個大寫字母S,你需要一個小寫之一。

+0

感謝您的回覆。但是我的努力失敗了。我得到了一個新的錯誤「無法將Curl :: Easy轉換爲String(TypeError)。」 – san6086

+0

您可以嘗試先在IRB會話中編輯您的代碼。它會在每一步之後告訴你,你輸入的內容是什麼。 – FlyingFoX