NoSQL JSON access

0 votes

Hi,

About NoSQL JSON access

In PHP

 

$jsonString = '
{                                           
  "orderID": 12345,                         
  "customerName": "Michael Scofield",              
  "customerEmail": "michael@xxxx.com",  
  "contents": [                             
    {                                       
      "productID": 43,                      
      "productName": "0000000000",         
      "quantity": 6                        
    },                                      
    {                                       
      "productID": 27,                      
      "productName": "111111111",        
      "quantity": [
 {
  "test1":"test1test1test1",
"test2":"test2test2test2",
"test3":[
{
"mytest1":"3D",
"mytest2":"4D",
"mytest3":"5D"
}
]
 }
 ]                         
    }                                       
  ],                                        
  "orderCompleted": true                    
}                                           
';
 
$test = json_decode( $jsonString );
echo $test->customerEmail . "<br />";
echo $test->contents[1]->quantity[0]->test3[0]->mytest3 . "<br />";
I can get
michael@xxxx.com
5D
If we insert above json code in NoSQL, can we get "5D" directly use any api call, rather than get all json code and parse json code to get "5D" ?
 
If yes, how can I do ?
 
Is there parse JSON code in APP42 services ?
like api call or other method
 
Thank you ?
asked Apr 11, 2014 in App42 Cloud API-BaaS by guo (110 points)

1 Answer

0 votes
 
Best answer
Hi guo,
For the above query you can use this code Snippet -
 
$selectKeys = array();
array_push($selectKeys, "customerEmail");
array_push($selectKeys, "contents.quantity.test3.mytest3");
$storageService->setSelectKeys($selectKeys);
$storage = $storageService->findAllDocuments($dbName, $collectionName);        
$jsonResponse = $storage->toString();
print_r("Response of Find All Documents : " . $jsonResponse );
$jsonDocList = $storage->getJsonDocList();
foreach ($jsonDocList as $jsonDoc) 
{
print_r("jsonDocs is : " . $jsonDoc->getJsonDoc() );
}

 

answered Apr 11, 2014 by samita.mahajan (60 points)
selected Apr 13, 2014 by guo
Hi,
Thanks for your reply !
Can you give me this for Android and iOS ?
Because our engineers use Android and iOS.

Thank you very much !
Hi guo,

1- Code Snippet For Android

Set<String> selectKeys = new HashSet<String>();
selectKeys.add("<Name_Of_the_Key>");
storageService.setSelectKeys(selectKeys);

2- Code Snippet For iOS (**Note** If you using SelectKeys download latest sdk version )

NSMutableArray *selectKeys = [NSMutableArray arrayWithObjects:@"First Name", nil];
[storageServiceObject setSelectKeys:selectKeys];
Hi,
In NoSQL, if my document is " {"phone":"000-000-000","age":45,"name":"Jordan"} ".
If I just want to modify name directly on one api call, how could I do ?

※Not get complete document -> parse document -> and store document

Could give me php, android and ios snippet ?

Thank you !
Hi guo ,
you can use addOrUpdateKeys() method. Code Snippet is here. http://api.shephertz.com/app42-docs/nosql-storage-service/#add_or_update_keys_with_json_string
Hi,
Thank you for your reply !
On iOS, this method is Not Available.
Could this method available on iOS in the future ?

Thank you !
Thank you very much !
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
...