json object not being saved into the database?

0 votes

if (GUI.Button (new Rect (5020020030), "Set Up Money")) {
            storageService = sp.BuildStorageService (); //building StorageService.
            JSONClass json = new JSONClass();
            App42API.SetLoggedInUser(PlayerPrefs.GetString("userName")); 
            json.Add("Money"PlayerPrefs.GetInt("Money"));
            storageService.InsertJSONDocument(dbNamecollectionNamejsoncallBack);

 

so when I click the button I don't get an error and it runs the OnSuccess() method from callBack but when I go into my database on the cloud it says I havn't saved any app data

http://imgur.com/2HlD7WC

 

asked Mar 10, 2014 in App42 Cloud API-BaaS by JoeCrill (25 points)
edited Mar 10, 2014 by JoeCrill

1 Answer

0 votes
What is "bacon_json" in your code. Have you correctly selected your DB name Collection name in AppHq console.
answered Mar 10, 2014 by sshukla480 (407 points)
Ok I figured it out. Got it now thanks.
ok but under JSON Document all I have are {} is there anyway I can get it to display the money amount in there?

Also
storageService.FindDocumentByKeyValue(dbName, collectionName, key, value, new UnityCallBack());
If the thing I'm trying to get from the storageService IS the value how would I do that? If I'm trying to get the user's amount of money by using the above method and the user's amount of money is the value of the key "money" how would that work?
ok think you want to save "int" in your JSON Document , SimpleJSON is not support  
other then string values yet. if you want to save this you must use our insertJSONUsingDictionary or simple create a JSON string like this:
"{\"money\":500}"
In the example it gives-

String dbName = "<Your_DataBase_Name>";  
String collectionName = "<Your_Collection_Name>";   
JSONClass json = new JSONClass();  
json.Add("name","Nick");  
json.Add("age",30);  

so how come here it's adding the value for age as an integer. There's no way to have it display that 30 in the database?
Try this ..
Query query = QueryBuilder.SetLoggedInUser("<Your User Name>");
storageService.FindDocumentsByQuery("<DB Name>","<Collection Name >",query);
This will return all documents related with your user like his money etc.
As i said you must use insertJSONUsingDictionary or simple create a JSON string like this "{\"money\":500}".
This is known issue in our side related with SimpleJSON we will fix this as soon as possible.
ok I got it working with the "{\"money\":500}". But how would I set the money to a variable instead of just putting in 500? I've never seen that format so not really sure how to do it.
also for InsertJSONUsingDictionary what are the parameters needed and what needs to be imported before I can use it?
Ok so I'm starting to get the hang of this. But now I'm having a problem with updating the json string.

this was the original string i added to the cloud - string json = "{\"Money\":500}";
all went well and it's there. But now to update it to 1000 I'm trying this -

string newJsonDoc = "{\"Money\":1000}";
storageService.UpdateDocumentByKeyValue(dbName,collectionName,"Money","500", newJsonDoc, callBack);

Getting the error "Document by key 'Money' and value '500' does not exist."
Because you pass your money value as a string in update method.Please use UpdateDocumentByQuery instead of  UpdateDocumentByKeyValue something like this .
Query q = QueryBuilder.Build("Money", 500, Operator.EQUALS);
                       storageService.UpdateDocumentByQuery(DBName, collectionName, q,  "{\"Money\":1000}", callBack);
For insert using Dictionary like this.
 Dictionary<string,object> json = new Dictionary<string,object>();
 json.Add("Money",55000);
 storageService.InsertJSONDocument(DbName,CollectionName, json, callBack);
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...