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

查看:302
本文介绍了反序列化匿名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"}
]

我尝试了反序列化使用 CL_TREX_JSON_SERIALIZER ,但它已损坏且无法与我的JSON配合使用,这就是原因

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

然后我尝试了 / UI2 / CL_JSON ,但是它需要一个完全适合对象的结构由JSON对象提供。在我的情况下,结构是指内部对象的内部表,这些对象的属性为时间,日期,时间戳,级别,消息详细信息。问题是:它不能正确处理引用,并使用类描述来描述分配给字段符号的字段。由于我无法获得对象列表,而只能获得该对象的引用列表,因此该解决方案也不起作用。

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

我的主要观点:


  • 我不想更改JSON,因为这是我从 sap.ui.log

  • 我更喜欢使用内置功能,而不是第三方框架

推荐答案

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

/UI5/CL_JSON_PARSER parses JSONs with unknown format.

请注意,上面多次写着供内部使用,以至于您p强烈应该认真对待它并克隆其代码以对其进行修复。

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天全站免登陆