我有一个混乱的阵列来自其他地方:
["person: John, Comment:, id_number:1, he is a guitar player","person: James, Comment:, id_number:38, James remark goes here"]
我怎样才能进入这个
[
{name:"John",id_number:1,Comment:"he is a guitar player"},
{name:"James",id_number:38,Comment:"James remark goes here"}
]
答案 0 :(得分:0)
这样做:
=trim(right(substitute(a1, " ", rept(" ", len(a1))), len(a1)))
如果他们并不总是以正确的顺序,你可能会变得更加漂亮并尝试搜索出你想要的值。
祝你好运!答案 1 :(得分:0)
以下是如何使用.map
和 RegExp
["person: John, Comment:, id_number:1, he is a guitar player","person: James, Comment:, id_number:38, James remark goes here"].map(e => {
var m = e.match(/^person: ([^,]+), Comment:, id_number:([^,]+), (.*)$/);
return {"person": m[1], "id_number": +m[2], "Comment": m[3]};
});
// [
// {"person": "John", "id_number": 1, "Comment": "he is a guitar player"},
// {"person": "James", "id_number": 38, "Comment": "James remark goes here"}
// ]
我不能保证这会对API的所有输出起作用,因为它会产生错误的输出,实际上修复应该在源头