【问题标题】:Select right word in a json object在 json 对象中选择正确的单词
【发布时间】:2023-03-13 01:21:02
【问题描述】:

我是 javascript 和 JSON 的新手,所以请原谅我。 我想控制台。记录“时间”的时间

let json = "{ "time":"28-10-2021T23:20:28.402Z", "remoteIP":"192.168.1.1", "host":"www.serveurlardon.com" }";

how to console.log(json.time) <-- dont work // the output i want is 28-10-2021T23:20:28.402Z

非常感谢

【问题讨论】:

    标签: javascript html json web


    【解决方案1】:

    你应该像这样转义你的引号或使用简单的引号,否则你会在定义一个字符串时遇到一些麻烦:

    let json = '{ "time":"28-10-2021T23:20:28.402Z", "remoteIP":"192.168.1.1", "host":"www.serveurlardon.com" }';
    

    然后你需要解析你的json

    const parsedJson = JSON.parse(json);
    

    那你应该可以了

    console.log(json.time)
    

    console.log(json['time']
    

    【讨论】:

    • 非常感谢!
    • 没问题祝你好运:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多