反序列化匿名 JSON 数组? [英] Deserialize an anonymous JSON array?

查看:70
本文介绍了反序列化匿名 JSON 数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要反序列化的匿名数组,这里是第一个数组对象的示例

<预><代码>[{ "时间":"08:55:54","日期":"2016-05-27",时间戳":1464332154807,级别":3,"message":"registerResourcePath('', '/sap/bc/ui5_ui5/ui2/ushell/resources/')","详细信息":"","component":"sap.ui.ModuleSystem"},{"time":"08:55:54","date":"2016-05-27","timestamp":1464332154808,"level":3,"message":"URL 前缀设置为:","详细信息":"","component":"sap.ui.ModuleSystem"},{"time":"08:55:54","date":"2016-05-27","timestamp":1464332154808,"level":3,"message":"(默认):/sap/bc/ui5_ui5/ui2/ushell/resources/","details":"","component":"sap.ui.ModuleSystem"}]

我尝试使用 CL_TREX_JSON_SERIALIZER 进行反序列化,但它已损坏且不适用于我的 JSON,这是为什么

然后我尝试了 /UI2/CL_JSON,但它需要一个结构",完全适合 JSON 对象给出的对象.结构"在我的例子中是指具有属性time、date、timestamp、level、messagedetails的内部对象表.还有一个问题:它没有正确处理引用并使用类描述来描述分配给字段符号的字段.由于我无法获得对象列表,而只能获得对对象的引用列表,因此该解决方案也不起作用.

作为第三次尝试,我尝试了 CALL TRANSFORMATION,如 Horst Keller,但使用这种方法我无法读取匿名数组,这就是为什么

我的主要观点:

  • 我不想更改 JSON,因为这是我从 sap.ui.log
  • 得到的
  • 我更喜欢使用内置功能而不是第三方框架

解决方案

/UI5/CL_JSON_PARSER 解析未知格式的 JSON.

请注意,它上面多次写着供内部使用",您可能应该认真对待它并克隆其代码以修复它.

I got an anonymous array which I want to deserialize, here the example of the first array object

[
  { "time":"08:55:54",
    "date":"2016-05-27",
    "timestamp":1464332154807,
    "level":3,
    "message":"registerResourcePath ('', '/sap/bc/ui5_ui5/ui2/ushell/resources/')",
    "details":"","component":"sap.ui.ModuleSystem"},
  {"time":"08:55:54","date":"2016-05-27","timestamp":1464332154808,"level":3,"message":"URL prefixes set to:","details":"","component":"sap.ui.ModuleSystem"},
  {"time":"08:55:54","date":"2016-05-27","timestamp":1464332154808,"level":3,"message":"  (default) : /sap/bc/ui5_ui5/ui2/ushell/resources/","details":"","component":"sap.ui.ModuleSystem"}
]

I tried deserializing using CL_TREX_JSON_SERIALIZER, but it is corrupt and does not work with my JSON, here is why

Then I tried /UI2/CL_JSON, but it needs a "structure" that perfectly fits the object given by the JSON Object. "Structure" means in my case an internal table of objects with the attributes time, date, timestamp, level, messageanddetails. And there was the problem: it does not properly handle references and uses class description to describe the field assigned to the field-symbol. Since I can not have a list of objects but only a list of references to objects that solution also doesn't works.

As a third attempt I tried with the CALL TRANSFORMATION as described by Horst Keller, but with this method I was not able to read in an anonymous array, and here is why

My major points:

  • I do not want to change the JSON, since that is what I get from sap.ui.log
  • I prefere to use built-in functionality and not a thirdparty framework

解决方案

/UI5/CL_JSON_PARSER parses JSONs with unknown format.

Note that it's got "for internal use" written on it so many times that you probably should take it seriously and clone its code to fixate it.

这篇关于反序列化匿名 JSON 数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆