i am working on cocos2d-x project i will use my code for ios and android both. Now i am using json file to store unlock data but i don't know how to parse the data in cocos2dx. can i have brief tutorial (demo code) so that i can proceed with my project.
i have created json file and save data in it. i put demo of inside json file.
{
"id": "food",
"name": "cherry",
"price": "20 coins",
"unlock": {
"level": 15,
"advance_unlock_price": "200 coins"
}
}
You can use rapidjson that is a part of Cocos2d-x.
Using Rapidjson in Cocos2D-X: Creating a JSON Document in Code and Serializing it
Use rapid json if your game has big big scale otherwise you can use jsonccp it is lightweight but not good as compared to rapidjson.rapidjson more fast than any parser.
rapid json:
http://rapidjson.org/
jsoncpp:
https://github.com/open-source-parsers/jsoncpp
Related
I'm doing an app with angular since it's easy for me to make it work as a progressive web app, etc. In my app I have a blog section.
The problem is that I need to load a json files dynamically because I'm using it to make new post pages as entry blogs.
I need to know if i can create something like a folder named json and throw all my json files with the content of each post, keeping the angular parsing the folder and looking for new jsons while it's in run time. Or i must use a backend with some mongo or mysql bbdd?
You need to use backend to implement.
Try to receive the service response in JSON array as below:
{
"posts": [
{
"author": "Chinua Achebe",
"content": "abc"
},
{
"author": "Hans Christian Andersen",
"content": "def"
}
]
}
Just iterate over the posts array to display your posts
I am creating a local weather web app by applying data from openweathermap api.
THe instructions for openweathermap api recommend to use cityId to query the endpoint and get data for a specific city. The cityId's are stated to be found in a json file that can be downloaded from this link: weathermap api json
Each object in the json looks like this:
{
"id": 707860,
"name": "Hurzuf",
"country": "UA",
"coord": {
"lon": 34.283333,
"lat": 44.549999
}
},
{
"id": 519188,
"name": "Novinki",
"country": "RU",
"coord": {
"lon": 37.666668,
"lat": 55.683334
}
},
I first downloaded this json file and placed it in my project but it slows its performance down quite a bit so I did some research and thought that my best answer was creating a citylist table in postgresql where each city has an id and a jsonb column that would simply be a parsed city object from the json file.
My problem is I don't know how to load each object in the json to the postgres db without manually writing insert sql queries for each object.
What is the most efficient way to load this json file into postgres? Do i need to export the json from it's file and write a script in my project that imports the json, parses each object and converts it into a sql query string? That doesn't sound efficient and my gut tells me there's an easier way.
Suggestions on how to do this with postgres or any other approach would be appreciated.
Hard to admit it but I struggle to manage state in my cli go app. What I basically want is to manage a list of objects with their properties in a file on disk. I want to be able to add objects with their properties, update objects and/or their properties and remove them if needed.
I thought it would be easy to just have a yml or json file and edit it with some kind of library but it seems harder than it should for a go beginner like me.
An example would be the following json structure.
{
"servers":
[
{ "hostname": "gandalf", "ip": "192.168.1.10", "color": "red" },
{ "hostname": "bilbo", "ip": "192.168.1.11", "color": "blue" },
{ "hostname": "frodo", "ip": "192.168.1.12", "color": "yellow" }
]
}
Now I want to be able to add, remove and edit servers. It doesn't have to be json, yaml is fine as well.
Do you girls and guys have any suggestions (libs and an example) on how to do it? I already tried Viper but adding new objects or even editing the existing ones seems to be impossible.
For settings that need to be human readable and will primarily be edited by a human a yaml or json file seems fine.
If the state is both written and read by the program itself and a full fledged database seems overkill then I would use a file based database. Probably a simple key/value store like boltdb or sqlite if the data needs more structure.
I personally use boltdb in such a case, because it is very lightweight, superfast and I like its simplicity.
-- edit --
With json as a file structure the problem is that you need to write and read the entire file every single time. A edit would be a read of the entire file, unmarshalling the json, changing something in the unmarshalled object, marshalling it back to json and writing the entire file again.
Thats why I would only use this for settings that the program reads once on startup and that's it.
I'm new to Grails, and I'm stuck on the basic structure of my web-app
So far I've implemented a Grails app that renders one JSON file to a readable table.
example
Given JSON file below
{
"abbreviation": "EXAMPLE",
"guid": "31ac235e2-3ad3-43e3-1fd4-41e6dfwegf03",
"metadata": {
"dataOrigin": "Example"
},
"rooms":
[
],
"site": {
"guid": "31ac235e2-3ad3-43e3-1fd4-41e6dfwegf03"
"title": "Example Testing"
}
}
My app renders above JSON file to below
Abbreviation : Example
GUID : 31ac235e2-3ad3-43e3-1fd4-41e6dfwegf03
Metadata : - DataOrigin : Example
Rooms : []
Site - GUID : 31ac235e2-3ad3-43e3-1fd4-41e6dfwegf03
Title : Exmaple Testing
Now, what should I do if I want my app to read JSON files with different Name/value pairs and renders it similarly to what my app does now?
(I've hard coded the application I have now)
I know this question is very vague, but can anyone give me any directions or insights on how to do this?
I'm afraid if there was a simply answer to this question then half of the web developers would be out of their jobs :-)
Anyway, there's probably several steps that could help in achieving your goal.
JSONSlurper(http://docs.groovy-lang.org/latest/html/gapi/groovy/json/JsonSlurper.html) to read JSON files. Obviously if you go for predefined structures you could use GSON (https://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/Gson.html) or similar library.
To display arbitrary data you can use the Grails Fields plugin(https://grails.org/plugin/fields).
I know it's all only pointers.
Is there a way to bulk load the data below into elasticsearch without modifying the original content? I POST each object to be a single document. At the moment I'm using Python to parse through individual objects and POST them one at a time.
{
{"name": "A"},
{"name": "B"},
{"name": "C"},
{"name": "D"},
}
Doing this type of processing in production from REST servers into elasticsearch is taking a lot of time.
Is there a single POST/curl command that can upload the file above at once and elasticsearch parses it and makes each object into its own document?
We're using elasticsearch 1.3.2
Yes, you can do bulk api via curl by using the _bulk endpoint. But not custom parsing. Whatever process that creates the file can format it to ES specification if that is an option. See here:
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-bulk.html
There is also bulk support in python via helper. See here:
http://elasticsearch-py.readthedocs.org/en/master/helpers.html