简体   繁体   中英

How to access SuperObject object if key contains dots (e.g. Ip address)?

The code fails to access JSON object if it's key contain dots.

JSON:

"TableTraps": {    
  "1.3.6.1.4.1.100.108.0.3": {
    "Vars": [ 
      "alarmDescription", 
      "alarmPositionUnit", 
      "alarmChannel"
    ]
  },
  "1.3.6.1.4.1.100.108.0.4": {
    "Vars": [ 
      "alarmDescription", 
      "alarmPositionUnit", 
      "alarmChannel"
    ]
  },
}

Pascal SuperObject code:

TableTraps := LoadFromFile();
TrapOID := '1.3.6.1.4.1.100.108.0.3';
trapInfo := TableTraps.O[TrapOID];

Results in trapInfo == nil but I expect SuperObject instance. I've tried to wrap the json key:

TrapOID := '"' + '1.3.6.1.4.1.100.108.0.3' + '"';

or

TrapOID := '''' + '1.3.6.1.4.1.100.108.0.3' + '''';

It doesn't help.

How should I call SuperObject to access the object instance if the json key contains dots?

Related question How to serialize JSON key containing dots (like eg IP address) with SuperObject?

Related question helped me to find the solution. The suprobject.O called directly on the parsed object parses dots as JSONPath. So instead of accessing "1.3.6.1.4.1.100.108.0.3: {}" it tries to access this JSON:

"1": { "3": { "6": { "1": { "4": { "1": { "100": { "0": { "3": value

Here the workaround:

TableTraps := LoadFromFile();
TrapOID := '1.3.6.1.4.1.100.108.0.3';
trapInfo := TableTraps.AsObject.O[TrapOID]; // NOTE: AsObject is required!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM