我正在尝试使用 JSONObject 和 JSONArray 类创建一个 json 对象(从根到叶节点)并以 json 格式从我的子兄弟树结构中递归打印 JSONObject 和 JSONArray 类,但我不断收到“无法解析类 JSONObject”错误。我的代码片段如下:
void screenout(Nope roota, Map mapp) {
me = roota;
Nope temp = roota;
if (roota == null)
return;
def rootie = new JSONObject();
def infos = new JSONArray();
while (temp != null) {
def info = new JSONObject();
info.put("category", temp.val)
info.put("path", mapp[temp.val])
infos.add(info);
roota = temp;
temp = temp.sibling;
screenout(roota.child, mapp);
}
rootie.put("children", infos);
if (me == root) {
println(rootie.JSONString());
}
}
Run Code Online (Sandbox Code Playgroud) 我的 redux 存储中有这些数据,我想在我的 react 组件中呈现这些数据。
{
"entityMap":{
"0":{
"type":"LINK",
"mutability":"MUTABLE",
"data":{"url":"www.google.co.in"}
}
},
"blocks":[
{
"key":"9k5h7",
"text":"this is the link",
"type":"unstyled",
"depth":0,
"inlineStyleRanges":[],
"entityRanges":[
{
"offset":12,
"length":4,
"key":0
}
],
"data":{}
}
]
}
Run Code Online (Sandbox Code Playgroud)
我成功地使用草稿编辑器创建了一个链接类型,并且能够将它存储在数据库中,并且在渲染它时我得到了除链接之外的整个文本。我的 redux 中有这个链接信息,即“实体映射”和“块”内的“entityRanges”,它告诉链接从哪个偏移量开始以及长度是多少。例如,在我的情况下,它是“这是链接”中的“链接”。
这是我用来从我的 redux 呈现上述 json 的代码:
render(){
return(
<div>
{
var nn = abovejsonfromreduxstore;
var editorState = EditorState.createWithContent(convertFromRaw(JSON.parse(nn)));
return (
<div>
<pre>
<Editor
editorState={editorState}
readOnly
/>
</pre>
</div>
</div>
}
</div>
);
Run Code Online (Sandbox Code Playgroud)
}
如何修改此呈现方法以使其也呈现链接实体?