1

Using TBackEndUsers mBaaS component, in order to populate the _push column of new Kinvey user, I have to pass JSONObject UserData to the procedure:

BackendUsers1->Users->SignupUser(AUserName, AUserData, AUserData, ACreatedObject);

Here is the piece of json requested:

{
  "_push" : 
  {
    "_devicetokens": [
      "ffcde6a5918106507a460d9709462f5ba37f70aa76d64fa21a4bfd.........."
    ]
  }
}

This is the wrong piece of json that I obtained with the source code below:

{
  "_push" : 
  {
    "_devicetokens" : "[\"ffcde6a5918106507a460d9709462f5ba37f70aa76d64fa21a4bfd..........\"]"
  }
}

What I am doing wrong?

#define TOKENS "ffcde6a5918106507a460d9709462f5ba37f70aa76d64fa21a4bfd.........."

void __fastcall TMainForm::CreateUserButtonClick(TObject *Sender)
{
TBackendEntityValue ACreatedObject;
TJSONObject *JSONObject, *JSONPush;
TJSONPair *Pair, *Pair2;
TJSONArray *Array;
  JSONObject = new TJSONObject;
  Pair = new TJSONPair("first_name", FirstNameEdit->Text);
  JSONObject->AddPair(Pair);
  Pair = new TJSONPair("last_name", LastNameEdit->Text);
  JSONObject->AddPair(Pair);
  Pair = new TJSONPair("email", EMailEdit->Text);
  JSONObject->AddPair(Pair);
  Array = new TJSONArray;
  Array->Add((String) TOKENS);
  Pair2 = new TJSONPair("_devicetokens", Array->ToString());
  JSONPush = new TJSONObject(Pair2);
  Pair = new TJSONPair("_push", JSONPush);
  JSONObject->AddPair(Pair);    
  BackendUsers1->Users->SignupUser(UserIdEdit->Text, PasswordEdit->Text, JSONObject, ACreatedObject);    
  delete JSONObject;
}
//---------------------------------------------------------------------------
TLama
  • 75,147
  • 17
  • 214
  • 392
Giovanni
  • 89
  • 1
  • 8
  • You've explicitly asked to produce a string from that array when you were creating `Pair2` in `TJSONPair("_devicetokens", Array->ToString());`. You've certainly wanted to write just `TJSONPair("_devicetokens", Array);`. – TLama Oct 31 '14 at 09:06
  • 2
    Thank you TLama, you are right. The problem is solved! – Giovanni Oct 31 '14 at 10:15

0 Answers0