简体   繁体   English

尝试使用 JSON - 我做错了什么? [等候接听]

[英]Trying to work with JSON - What am I doing wrong? [on hold]

I am using a XMLHttpRequest to get a file, let's say someData.json which holds the following data:我正在使用XMLHttpRequest来获取文件,假设someData.json包含以下数据:

{
    "language" : "english",
    "somethingElse" : "Hello world!",
}

When my callback function from the XMLHttpRequest is triggered the data is supplied as argJSONData .当我的来自 XMLHttpRequest 的回调XMLHttpRequest被触发时,数据作为argJSONData提供。 Now I am trying to work with my data, for example现在我正在尝试处理我的数据,例如

function processJSONData(argJSONData)
{
    var myLanguage = argJSONData.language;
}

In this case, myLanguage is undefined although logging argJSONData shows up correctly, so I tried parsing the data into the JSON format like this在这种情况下, myLanguageundefined的,尽管日志记录argJSONData显示正确,所以我尝试将数据解析为 JSON 格式,如下所示

JSON.Parse(argJSONData);

which gives me this error message in my web console这在我的 web 控制台中给了我这个错误消息

TypeError: JSON.Parse is not a function

so I tried converting it into an array using所以我尝试使用将其转换为数组

Array.from(argJSONData);

which made a huge array where each character is a hole entry, looking something like this这形成了一个巨大的数组,其中每个字符都是一个洞入口,看起来像这样

    0: "{"
​    1: "\r"
​​    2: "\n"
​​    3: " "
​​    4: " "
​​    5: " "
​​    6: " "
​    7: "\""
​    8: "l"
​​    9: "a"
   10: "n"

(this is not the end, but I think you get the idea) (这不是结束,但我想你明白了)

Any ideas how I can make it work?有什么想法可以让它发挥作用吗? I also tried replacing " with ' in my JSON file and much more, nothing works.我还尝试在我的 JSON 文件中将"替换为'等等,但没有任何效果。

I am grateful for any help/feedback.我很感激任何帮助/反馈。 Thank you.谢谢你。

Try using尝试使用

JSON.parse(argJSONData);

might just be capitalization issue可能只是大小写问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM