如果我希望将内容值作为JSON_OBJECT.item(“键”)的字符串使用而不必
some_json_value_as_string: STRING
do
if attached {JSON_STRING} l_json_o as l_s then
Result := l_s.unescaped_string_8
elseif attached {JSON_NUMBER} l_json_o as l_n then
Result := l_n.item.out
else
check
you_forgot_to_treat_a_case: False
end
end
end
用于json对象
{
| | "datasource_name": "DODBC",
| | "datasource_username": "dev_db_usr",
| | "datasource_password": "somePassword",
| | "ewf_listening_port": 9997,
| | "log_file_path": "/var/log/ewf_app.log",
| | "default_selected_company": 1,
| | "default_selected_branch": 1,
| | "default_selected_consumption_sector": 1,
| | "default_selected_measuring_point": 1,
| | "default_selected_charge_unit": -1
| }
带有io.putstring的{JSON_VALUE}.representation
是:
datasource_username=dev_db_usr
而不是仅值!
有没有办法做到这一点?我没有直观地发现JSON_VALUE的不同方法:值,因为out
方法提供了类和指针地址,对我而言,这确实与关联的json对象的字符串表示形式相去甚远。
答案 0 :(得分:0)
功能{JSON_VALUE}.representation
是当前JSON值的字符串表示形式。
好的,但是如果您有jo: JSON_OBJECT
,然后假设您有datasource_username_key: STRING = "datasource_username"
你可以做
if attached jo.item (datasource_username_key) as l_value then
print (l_value.representation)
end