【问题标题】:How to get odata.nextLink from the returned JSON object using oracle's apex_json如何使用 oracle 的 apex_json 从返回的 JSON 对象中获取 odata.nextLink
【发布时间】:2018-08-23 12:40:47
【问题描述】:

我正在从 odata 服务检索数据。响应包含一个用于加载更多数据的链接,即我需要检索以加载更多数据的 odata.nextLink。如何使用 oracle 的 apex_json 执行此操作? 服务器的响应是这样的:

{
  "odata.metadata":"http://localhost:60497/odata/$metadata#tables","value":[
    {"id":001,"name":"abc" }

      .
      .
  ],
"odata.nextLink":"http://localhost:60497/odata/tables?$skip=10"
}

通常我会解析数据,然后像next_link := apex_json.get_varchar2('odata.nextLink'); 这样检索信息,但因为它包含一个不起作用的点。

【问题讨论】:

    标签: json oracle oracle-apex


    【解决方案1】:

    在这种情况下:

    apex_json.get_varchar2('odata.nextLink');
    

    它正在考虑将 nextLink 作为 odata 的值。

    DECLARE
    
    v_json APEX_JSON.T_VALUES;
    v_str_json VARCHAR2(4000);
    next_link VARCHAR2(4000);
    
    BEGIN
    
    
    v_str_json := '{
      "odata" : {"nextLink" : "mylink"},
      "odata.metadata":"http://localhost:60497/odata/$metadata#tables","value":[
        {"id":001,"name":"abc" }
      ],
    "odata.nextLink":"http://localhost:60497/odata/tables?$skip=10"
    }
    }';
    
    APEX_JSON.PARSE(v_json, v_str_json);
    
    next_link := APEX_JSON.GET_VARCHAR2(p_path => 'odata.nextLink', p_values => v_json);
    
    dbms_output.put_line(next_link);
    
    END;
    
    >> OUTPUT: mylink
    
    • 我不知道如何从字面上解释“odata.nextLink”;而不是作为路径。

    如果没有人知道:

    1 - 或停止发送“odata”。每个属性名称的开头;

    2 - 或使用替换删除。

    【讨论】:

    • 我无法控制 odata 服务输出的内容。因此我暂时这样做(但我希望有更好的解决方案): apex_json.parse(replace(my_clob,'odata.nextLink', 'odata_nextLink') );链接:= apex_json.get_varchar2('odata_nextLink');
    猜你喜欢
    • 2017-12-25
    • 2018-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-12
    • 1970-01-01
    • 2016-10-13
    • 1970-01-01
    相关资源
    最近更新 更多