Share via


Simple JSON parser which I can include in my code

Question

Wednesday, December 12, 2018 12:55 AM

Hello,

I have this simple JSON file. I can read it and print and this how it looks. I Googled and there are many many parsers but all involve including a library. I can't do that in my project. All I can do cut and paste the parser inside my code. I tried writing on my own it was too clumsy. So if any one knows a simple copy/paste type json parser kindly let me know and pass the code. At the end of the parsing I need the values of lumen, volt, watts and current values available as integers for my usage. 

Thanks

{

    "myJsonFile": "1.0",
    "light" : {
      "lumen": 40,
      "volt": 110,
      "watts": 50,
      "current": 10
    }
 }

All replies (7)

Thursday, December 13, 2018 5:11 AM âś…Answered

Found one at https://github.com/udp/json-parser

Thanks to all I shall close this 


Wednesday, December 12, 2018 8:58 AM

Hi,

Thanks for posting here.

Are you looking for the C/C++ json parser? If so, I suggest you refer to the following link.
https://stackoverflow.com/questions/36471581/c-c-json-parser

Best Wishes,

Jack Zhang

MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


Wednesday, December 12, 2018 11:28 AM

You can use Windows.Data.Json Namespace

#include <windows.data.json.h>

in C++, but code a bit complicated

(tested in C++/Win32 on Windows 10)


Wednesday, December 12, 2018 2:51 PM

Hi Jack,

Thanks for the tips but I had checked this out and it will not work for me as it involves installing a product and getting a library. Sorry I should have mentioned I am using C/C++. I am looking for full code which I can copy and paste. 

Best Regards

ananda


Wednesday, December 12, 2018 3:11 PM

Hi Castorix,

I am using C/C++ language sorry forgot to mention. Windows.Data.Json Namespace is C# right? Did you mean to include a code? I did not see it. Kindly clarify. When I execute the printf() I get the following output. What I would like (ideally) is call MyJsonParser(jsonText.c_str(), &MyDataStruct) and get in return the struct filled. So I am looking for the function MyJsonParser() which exists in my program and has not special dependencies other than the default. Thanks

printf("%ws\n", jsonText.c_str());{    "myJsonFile": "1.0",
    "light" : {
      "lumen": 40,
      "volt": 110,
      "watts": 50,
      "current": 10
    }
 }

Wednesday, December 12, 2018 4:24 PM

I am using C/C++ language sorry forgot to mention. Windows.Data.Json Namespace is C# right?

It is WinRT and can be used in C/C++ with

#include <windows.data.json.h>
#pragma comment(lib, "runtimeobject.lib")
using namespace ABI::Windows::Data::Json;

Wednesday, December 12, 2018 5:00 PM

Please point me to the code. The code I mentioned earlier

>>So I am looking for the function MyJsonParser() which exists in my program and has not special dependencies other than the default

thanks

ananda