__
data = {"nodeDataArray": [
{"category": "Start", "text": "start", "key": -1},
{"category": "Logic", "text": "and", "key": -2},
{"category": "Logic", "text": "and", "key": -3},
{"category": "Operator", "text": "==", "key": -4},
{"category": "Operator", "text": "==", "key": -5},
{"category": "Logic", "text": "and", "key": -6},
{"category": "Operator", "text": ">=", "key": -7},
{"category": "Operator", "text": "<=", "key": -8},
{"category": "Variable", "text": "age", "key": -9},
{"category": "Variable", "text": "age", "key": -10},
{"category": "Constant", "text": "18", "key": -11},
{"category": "Constant", "text": "50", "key": -12},
{"category": "Variable", "text": "salary", "key": -13},
{"category": "Constant", "text": "5000", "key": -14},
{"category": "Variable", "text": "rent", "key": -15},
{"category": "Constant", "text": "1000", "key": -16}
],
"linkDataArray": [
{"from": -1, "to": -2},
{"from": -2, "to": -3},
{"from": -2, "to": -4},
{"from": -3, "to": -6},
{"from": -3, "to": -5},
{"from": -6, "to": -7},
{"from": -6, "to": -8},
{"from": -7, "to": -9},
{"from": -7, "to": -11},
{"from": -8, "to": -10},
{"from": -8, "to": -12},
{"from": -5, "to": -13},
{"from": -5, "to": -14},
{"from": -4, "to": -15},
{"from": -4, "to": -16}
]}
将上面数据转换成下面这种样子
上面数据中key表示当前节点,from为to的前面一个节点。上面的key和下面的to是对应的
{'and': [{'and': [{'and': [{'>=': [{'var': 'age'}, 18]}, {'<=': [{'var': 'age'}, 50]}]}, {'==': [{'var': 'salary'}, 5000]}]},{'==': [{'var': 'rent'}, 1000]}]}