Ruby   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了无法使用点语法进行ruby哈希大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
使用Net / http从Yahoo Placemaker API中提取一些json数据.收到回复后,我在响应中执行JSON.parse.这给我一个哈希,看起来像: @H_197_2@{"processingTime"=>"0.001493","version"=>"1.4.0.526 build 111113","documentLength"=>"25","document"=>{"administrativeScope"=>{"woEID"=>"2503863","type"=>"Town","name"=>"Tampa,FL,US","centroid"=>{"latitude"=>"27.9465","longitude"=>"-82.4593"}},"geographicScope"=>{"woEID"=>"2503863","localScopes"=>{"localScope"=>{"woEID"=>"2503863",US (Town)","longitude"=>"-82.4593"},"southWest"=>{"latitude"=>"27.8132","longitude"=>"-82.6489"},"northEast"=>{"latitude"=>"28.1714","longitude"=>"-82.2539"},"ancestors"=>[{"ancestor"=>{"woEID"=>"12587831","type"=>"county","name"=>"Hillsborough"}},{"ancestor"=>{"woEID"=>"2347568","type"=>"State","name"=>"Florida"}},{"ancestor"=>{"woEID"=>"23424977","type"=>"Country","name"=>"United States"}}]}},"extents"=>{"center"=>{"latitude"=>"27.9465","longitude"=>"-82.2539"}},"placeDetails"=>{"placEID"=>"1","place"=>{"woEID"=>"2503863","placeReferencEIDs"=>"1","matchType"=>"0","weight"=>"1","confidence"=>"8"},"referenceList"=>{"reference"=>{"woEIDs"=>"2503863","placeReferencEID"=>"1","placEIDs"=>"1","start"=>"15","end"=>"20","isPlaintextMarker"=>"1","text"=>"Tampa","type"=>"plaintext","xpath"=>""}}}}

我可以通过像jsonResponse [‘version’]这样的东西来访问元素,但是我无法做jsonResponse.version.为什么是这样?

解决方法

哈希没有点语法的键. OpenStruct确实: @H_197_2@require 'ostruct' hash = {:name => 'John'} os = OpenStruct.new(hash) p os.name #=> "John"

大佬总结

以上是大佬教程为你收集整理的无法使用点语法进行ruby哈希全部内容,希望文章能够帮你解决无法使用点语法进行ruby哈希所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。