gpt4 book ai didi

JavaScript 枚举

转载 作者:行者123 更新时间:2023-11-30 17:19:06 25 4
gpt4 key购买 nike

我有一个文件 [不是 .js 文件],其中有一个错误列表,错误代码按以下格式映射。

    404  = The requested resource could not be found
500 = Internal server error
1001 = No message body found
1002 = No message header found

等等....[大约3000行。]

我想写一个函数,将错误代码作为参数传递,并期望接收相应的字符串作为 errorString。

我正在为我的网络应用程序使用 Javascript。但不幸的是,包含这种格式的错误列表的文件。任何人都建议我应该做什么来完成工作。

我也准备将此文件转换为 java 脚本文件,如果有人可以建议我如何用大约 3000 行代码实现这一点。

谢谢。

最佳答案

I am also ready to convert this file to a java script file, if any body can suggest how would I achieve that for about 3000 lines of code.

使用任何称职的编辑器,您只需将 ", 附加到每一行,并将 = 替换为 :"。这会给你:

404: "The requested resource could not be found",
500: "Internal server error",
1001: "No message body found",
1002: "No message header found",

然后将文件中的最后一个逗号替换为};,并在开头添加var myObject = {,就完成了。

关于JavaScript 枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25509269/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com