在单引号之前将反斜杠插入字符串中,节点v8.11.4

时间:2018-09-07 13:43:34

标签: javascript node.js regex

我跟随“ Eloquent Javascript:第7章项目:机器人”,并且在使用 NODE v8.11.4 时在字符串中插入反斜杠时遇到问题。当我在Chrome的控制台中运行代码时,这些反斜杠不会显示 NOT

是否有一种方法可以防止插入这些反斜杠?

代码:

const roads = ["Alice's House-Bob's House", "Alice's House-Cabin", "Alice's House-Post Office", "Bob's House-Town Hall", "Daria's House-Ernie's House", "Daria's House-Town Hall", "Ernie's House-Grete's House", "Grete's House-Farm", "Grete's House-Shop", "Marketplace-Farm", "Marketplace-Post Office", "Marketplace-Shop", "Marketplace-Town Hall", "Shop-Town Hall"];

let edgeMap=edges.map(r=>r.split("-"))
console.log(edgeMap)

使用节点的输出:

[ [ 'Alice\'s House', 'Bob\'s House' ],
  [ 'Alice\'s House', 'Cabin' ],
  [ 'Alice\'s House', 'Post Office' ],
  [ 'Bob\'s House', 'Town Hall' ],
  [ 'Daria\'s House', 'Ernie\'s House' ],
  [ 'Daria\'s House', 'Town Hall' ],
  [ 'Ernie\'s House', 'Grete\'s House' ],
  [ 'Grete\'s House', 'Farm' ],
  [ 'Grete\'s House', 'Shop' ],
  [ 'Marketplace', 'Farm' ],
  [ 'Marketplace', 'Post Office' ],
  [ 'Marketplace', 'Shop' ],
  [ 'Marketplace', 'Town Hall' ],
  [ 'Shop', 'Town Hall' ] ]

1 个答案:

答案 0 :(得分:1)

不会插入反斜杠,这是var jsonT = '{"macid":"mac1234","attri":{"data":{"ch1":12,"ch2":123},"settings":{"log_time":"1min"}}}' var f = JSON.parse(jsonT); f.attri.data.ch1 = "hi" jsonT = JSON.stringify(f); console.log(jsonT); 函数的功能。这样就可以读取打印出的值。

尝试说:

def clean_object_id(self):
    if self.cleaned_data['object_id']:
        return int(self.cleaned_date['object_id'])

应该返回console.log