简体   繁体   English

在本机Tizen中解析JSON

[英]Parsing JSON in native Tizen

I've got a Native C project in which I need to parse some Json. 我有一个Native C项目,需要在其中解析一些Json。 According to something I found in Tizen documentation the json-glibc parser is included in the SDK. 根据我在Tizen文档中发现的内容,SDK中包含json-glibc解析器。 So I tried using it. 所以我尝试使用它。 Here is a minimal program that creates the parser and nothing more. 这是创建解析器的最小程序,仅此而已。

#include <json-glib.h>
main(int argc, char *argv[])
{
   JsonParser* jsonParser = NULL;
   GError *error = NULL;
   jsonParser = json_parser_new();

   if(jsonParser == NULL) {
       fputs("failed to create parser", stderr);
    exit(7);
   }
  return 0;
}

In the Tizen 3.0 emulator this works fine. 在Tizen 3.0模拟器中,这可以正常工作。 As soon as I try it in the 2.3.2 emulator or on 2.3.2 hardware it fails. 一旦在2.3.2仿真器或2.3.2硬件上尝试,它就会失败。 It strikes ms as odd that such a thing would be hardware/firmware dependent. 奇怪的是,这种事情将取决于硬件/固件。 Does anyone know if there is something I should do so that I can create the parser on either version of the hardware? 有谁知道我应该做些什么,以便可以在任一版本的硬件上创建解析器?

Update 10月6日2018年 更新10月6日2018年

I think this is a bug with the 2.3.x emulator for more recent installs. 我认为这是2.3.x模拟器中最新安装的错误。 This is only a hypothesis as the most I can do is try fresh installs on fresh operating systems. 这只是一个假设,因为我最多只能尝试在全新的操作系统上进行全新安装。 My only other hypothesis is that there is some component that the 2.3.x emulator needs to function that is missing and not documented as a requirement. 我唯一的另一个假设是,2.3.x仿真器需要一些组件才能正常运行,而这些组件没有记录下来,也没有作为要求记录在案。

+-----------------------------------+------+--------+--------------------------+
|            OS Version             | Tizen|Studio  |          Result          |
+-----------------------------------+------+--------+--------------------------+
| Ubuntu 16 LTS Clean Install       | 2.3  |    2.4 | json_parser_new()== NULL |
| Ubuntu 16 LTS Clean Install       | 2.3  |    2.5 | json_parser_new()== NULL |
| Ubuntu 18 LTS Clean Install       | 2.3  |    2.4 | json_parser_new()== NULL |
| Ubuntu 18 LTS Clean Install       | 2.3  |    2.5 | json_parser_new()== NULL |
| Mac OS X High Siera Clean Install | 2.3  |    2.5 | json_parser_new()== NULL |
| Mac OS X Movaje Clean Install     | 2.3  |    2.5 | json_parser_new()== NULL |
| Windows 10 Creator's Edition      | 2.3  |    2.5 | json_parser_new()== NULL |
| Windows 10 Creator's Edition      | 2.3  |    2.4 | json_parser_new()== NULL |
| Ubuntu 16 LTS Clean Install       | 3.0  |    2.4 | success                  |
| Ubuntu 16 LTS Clean Install       | 3.0  |    2.5 | success                  |
| Ubuntu 18 LTS Clean Install       | 3.0  |    2.4 | success                  |
| Ubuntu 18 LTS Clean Install       | 3.0  |    2.5 | success                  |
| Mac OS X High Siera Clean Install | 3.0  |    2.5 | success                  |
| Mac OS X Movaje Clean Install     | 3.0  |    2.5 | success                  |
| Windows 10 Creator's Edition      | 3.0  |    2.5 | success                  |
| Windows 10 Creator's Edition      | 3.0  |    2.4 | success                  |
+-----------------------------------+---------------+--------------------------+

From these results one would think that Tizen 2.3 isn't supported. 从这些结果中,我们会认为不支持Tizen 2.3。 But it is and it appears that people that have installed Tizen Studio sometime before now can successfully execute the same code. 但是,现在看来,已经安装Tizen Studio的人现在可以成功执行相同的代码。

enter link description here I got an answer to my question over the the Tizen developer's forums. 在这里输入链接描述,我在Tizen开发者论坛上得到了我的问题的答案。

Long story short, the Gear S3+ and the Gear S2 use different versions of GLIB. 长话短说,Gear S3 +和Gear S2使用不同版本的GLIB。 On the one used on the Gear S2 is glib_init() isn't called first attempts to create objects will fail. 在Gear S2上使用的是glib_init(),没有被调用,第一次创建对象的尝试将失败。

The following needs to be added before using any glib library to avoid this problem. 使用任何glib库之前,需要添加以下内容,以避免出现此问题。

#if !GLIB_CHECK_VERSION(2, 35, 0)
g_type_init();
#endif

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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