【发布时间】:2017-03-31 11:02:35
【问题描述】:
您好,我正在尝试提取此内容("Polk County", "short_name" => "Polk County") 在这个哈希的第三行,但我似乎只能得到“波尔克县” 这是我当前的代码:
{% for county_hash in location.address_components %}
{% for county in county_hash %}
{{ county.long_name }}
{% endfor %}
{% endfor %}
{
"0" => {
"long_name" => "426", "short_name" => "426", "types" => ["street_number"]
}, "1" => {
"long_name" => "Swanee Drive", "short_name" => "Swanee Dr", "types" => ["route"]
}, "2" => {
"long_name" => "Livingston", "short_name" => "Livingston", "types" => ["locality", "political"]
}, "3" => {
"long_name" => "Polk County", "short_name" => "Polk County", "types" => ["administrative_area_level_2", "political"]
}, "4" => {
"long_name" => "Texas", "short_name" => "TX", "types" => ["administrative_area_level_1", "political"]
}, "5" => {
"long_name" => "United States", "short_name" => "US", "types" => ["country", "political"]
}, "6" => {
"long_name" => "77351", "short_name" => "77351", "types" => ["postal_code"]
}, "7" => {
"long_name" => "8238", "short_name" => "8238", "types" => ["postal_code_suffix"]
}
}
【问题讨论】:
-
位置文件是什么样的?
-
它将显示LocationDrop方法,该方法能够显示地址,州邮政等
-
使用上面的迭代代码会给我这个结果'426 Swanee Drive Livingston Polk County Texas United States 77351 8238',但我只需要“Polk County”
-
有缺失的信息完全理解问题,你应该发布相关文件内容stackoverflow.com/help/mcve
标签: for-loop iteration jekyll shopify liquid