dongwei5740
dongwei5740
2019-08-20 04:20

使用PHP从Google表格JSON数据中回显特定值

已采纳

I'm trying to figure out "how-to" echo out the "tbenrud@gushd.net" (red arrow pointing to it) value from this JSON file. I can echo $data[feed][entry][1][id], but I run into trouble when I get to gsx$emailaddress. I assume it is because of the $ in the label. I do not have control over the label name (created by Google Sheets).

Any help is greatly appreciated.

enter image description here

My Code

$urlSheet = 'https://spreadsheets.google.com/feeds/list/1s7UCtbRY2dU3YdDu_kjnr-_y5Lh49yMHQRzgiDt8D4c/2/public/values?alt=json';
$jsonSheet = file_get_contents($urlSheet);
$data = json_decode($jsonSheet, true);

Thank you!

Todd

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • doukuo9116 doukuo9116 2年前

    If you use single quotes, the $ won't trigger PHP variable interpolation.

    echo $data['feed']['entry'][1]['gsx$emailaddress']['$t'];
    
    点赞 评论 复制链接分享
  • duanjiao5723 duanjiao5723 2年前

    Try "escaping" the $ sign like this:

    'gsx{$}emailaddress'
    
    点赞 评论 复制链接分享

相关推荐