JavaScript

JSで多階層のJSONを扱う時の備忘録

経緯

 GAS使うことになった

function test() {
  var testJson = '{"replyToken":"897aa08fd48247f5aa2aa99999999999", "source":{"type":"user", "userId":"U911cc758e62b359634cd299999999999"}, "type":"message", "message":{"id":"6906513233888", "text":"なまなまか", "type":"text"}, "timestamp":"1.50917625936E12"}';
  var response = JSON.parse(testJson);
  var source = response.source;
  var s_source     = JSON.stringify(source);
  var sourceArr     = JSON.parse(s_source);
  var userId        = source.userId;
  Logger.log(source);
  Logger.log(s_source);
  Logger.log(sourceArr);
  Logger.log(userId);

}