how can i add int array app42 JSON collection?

–1 vote

JSONObject jsonBattleInfo = new JSONObject();  

    try {

    int[] nItemUIDArray = new int[180];

    for (int i = 0; i < 180; i++) {

        nItemUIDArray[i] = i+1;

    };

   jsonBattleInfo.put( "Inventory", nItemUIDArray );

but int array do not entered my json collection like this "Inventory": "[I@43187598",

{
  
  "Inventory": "[I@43187598",
  "install1": 0,
  "install2": 0,
 }

how can i int array put my json app42 collection?

I want to int array add like this 

"Inventory" : {1,2,3,4,5......,179,180} 

 

 

 

asked Feb 4, 2016 in Android by zetcrusader (13 points)
recategorized Mar 8, 2016 by shepAdmin

1 Answer

+1 vote

Hi,

I tried your code with App42 Storage Service as follows:

        StorageService storageService = sp.buildStorageService();
        JSONObject jsonBattleInfo = new JSONObject();  
    
            int[] nItemUIDArray = new int[180];

            for (int i = 0; i < 180; i++) {

                nItemUIDArray[i] = i+1;

            };
           
            jsonBattleInfo.put( "Inventory", nItemUIDArray );
            System.out.println(jsonBattleInfo);
            
            Storage storageObj = storageService.insertJSONDocument("queryTest",
                    "foo", jsonBattleInfo);
            System.out.println(storageObj);

The response is as follows:

{"app42":{"response":{"success":true,"storage":{"dbName":"queryTest","collectionName":"foo","jsonDoc":{"_$createdAt":"2016-02-05T06:50:34.258Z","_$updatedAt":"2016-02-05T06:50:34.258Z","Inventory":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180],"_id":{"$oid":"56b4463a2b10485287eb03cb"}}}}}}

The last line of the question say like you want to add int array like this 

"Inventory" : {1,2,3,4,5......,179,180}

Which is same as the response i got.

Could please provide some more detail on the problem you are facing?

Thanks.

answered Feb 5, 2016 by rajeev.etc (1,660 points)
thank you for your help!
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
...