我有一个看起来像这样的json
let ini2Obj = {};
const keyValuePair = kvStr => {
const kvPair = kvStr.split('=').map( val => val.trim() );
return { key: kvPair[0], value: kvPair[1] };
};
const result = document.querySelector("#results");
document.querySelector( '#inifile' ).textContent
.split( /\n/ ) // split lines
.map( line => line.replace( /^\s+|\r/g, "" ) ) // cleanup whitespace
.forEach( line => { // convert to object
line = line.trim();
if ( line.startsWith('#') || line.startsWith(';') ) { return false; }
if ( line.length ) {
if ( /^\[/.test(line) ) {
this.currentKey = line.replace(/\[|\]/g,'');
ini2Obj[this.currentKey] = {};
} else if ( this.currentKey.length ) {
const kvPair = keyValuePair(line);
ini2Obj[this.currentKey][kvPair.key] = kvPair.value;
}
}
}, {currentKey: ''} );
result.textContent +=
`**Check: ini2Obj['Slave_Settings:11'].ConfigurationfilePath = ${
ini2Obj['Slave_Settings:11'].ConfigurationfilePath}`;
result.textContent +=
`\n\n**The converted object (JSON-stringified)\n${
JSON.stringify(ini2Obj, null, ' ')}`;
我旨在使它去毛刺并构造Scala对象。这是它的模型
var cutJson =
"""
|{
| "routingKey": "event.orders.status.paid",
| "jsonClass" : "Event"
|}
""".stripMargin[enter image description here][1]
这是应该去粗麻的行
case class Order(routingKey: String, jsonClass: String)
程序崩溃并显示以下错误,但是,如果我仅使用routingKey参数,则效果很好