how to convert json object to a simple list #2355
-
I am new to this area. I am trying to use json library https://github.com/nlohmann/json to parse out data in the JSON feed , and construct a simple list that the user go through with keyboard How do I do this? This is what I know so far based on your documentation // read a JSON file How do I convert jsonObject into a simple list? |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 3 replies
-
How does the JSON file look like? What do you mean with “simple list”? |
Beta Was this translation helpful? Give feedback.
-
Thank you so much for your response. This is an example of the json file I just want to be able to parse the file, display the contents and use the up,down,left and right arrows on the key board to scroll through the formatted list. I truly appreciate you taking the time to do this. |
Beta Was this translation helpful? Give feedback.
-
Thank you so much for the information. I need your help again. I am getting an error. I copied the contents from the url feed into a file called "stats.json", and put it in my project directory. It builds fine but when I try to execute, I get the following error: terminate called after throwing an instance of 'nlohmann::detail::parse_error' Process finished with exit code 3 |
Beta Was this translation helpful? Give feedback.
-
Thank you so much for your help. Is there anyway I can read and parse the contents of this website directly? I know I can read from a file, but what about from a website like the example below? This is an example of the json file |
Beta Was this translation helpful? Give feedback.
-
I have a question for you. For this discussion I will use a file called help.cpp When I use CLION IDE, and use it works fine. I am able to build help.cpp and run my program siuccessfully. If I try to build the same help.cpp file on ubuntu, it fails and complains about <json.hpp>. I get the follow error: Cannot open the files for reading On Ubuntu I installed the following json: I hope you can help me. I have spent all day working on it. I have been up for over 18 hours and I am concerned I will cause more harm than good at this point. Please help. |
Beta Was this translation helpful? Give feedback.
-
OK... I definitely need to go to bed. I believe I just found the issue. This is the line of code I have to read the file: std::string input_file = R"(C:\Users\Josep\CLionProjects\untitled5\stats.json)"; ubuntu does not recognize the path so I copied the file into my project directory and it worked. Thank you |
Beta Was this translation helpful? Give feedback.
Thank you so much for your response.
This is an example of the json file
http://statsapi.mlb.com/api/v1/schedule?hydrate=game(content(editorial(recap))),decisions&date=2018-06-10&sportId=1
I just want to be able to parse the file, display the contents and use the up,down,left and right arrows on the key board to scroll through the formatted list.
I truly appreciate you taking the time to do this.