美文网首页
typescript 与小程序的res.data json对象解

typescript 与小程序的res.data json对象解

作者: 吉凶以情迁 | 来源:发表于2022-03-28 11:14 被阅读0次

下面代码是处理服务器是脏数据json用()包裹的情况以及纯json的情况 ,json对象类型打印是object直接转换为类型Record<string, any>即可。

    if (typeof (res.data) == "string") {
                    var result = res.data.replace(/\(|\)/g, "");
                    console.debug("result:" + result);
                    var obj: object = JSON.parse(result);
                    console.debug("obj:" + (typeof obj));
                    datax = obj as Record<string, any>;
                } else {
                    datax = res.data as Record<string, any>;
                }

相关文章

网友评论

      本文标题:typescript 与小程序的res.data json对象解

      本文链接:https://www.haomeiwen.com/subject/ofhpjrtx.html