Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.09 KB | None | 0 0
  1. // Warstwa 0 (static) wycinanie elementu z bieżącego roota (do wywoływania na przemian)
  2. JsonGetElementFromObject(char* jsonObject, unsigned int size, JsonType_e type, void* output, unsigned int outputSize, char* elementName); // Wycina element (string) z obiektu json
  3. JsonGetElementFromArray (char* jsonTable,  unsigned int size, JsonType_e type, void* output, unsigned int outputSize, int elementIndex);  // Wycina element (string) z tablicy json
  4.  
  5.  
  6. // Warstwa 1 wycinanie elementu wg scieżki
  7. JsonGetElement          (char* json,       unsigned int size, JsonType_e type, void* output, unsigned int outputSize, char* path, ...);       // Wyszukuje i wycina element o podanej ścieżce
  8.  
  9.  
  10. // Warstwa 2 strukturyzacja wycinania elementów
  11. typedef struct
  12. {
  13.     char*           path;
  14.     JsonType_e      type;
  15.     void*           output;
  16.     unsigned int    outputSize;
  17. }
  18. JsonParseInfo_t;
  19.  
  20. JsonParse               (char* json,       unsigned int size, JsonParseInfo_t* parseTable);                                               // Wywołuje JsonGetElement w pętli z parametrami podanymi w parseTable
  21.  
  22.  
  23.  
  24. // Użycie strukturalne:
  25.  
  26. char json[HTTP_RESPONSE_BUFFER_SIZE];
  27. char courierId[COURIER_ID_LEN + 1];
  28. char password[MAX_PASSWORD_LEN_ASCI_MD5 + 1];
  29. char sessionuuid[RAPI_MAX_UUID_LEN + 1];
  30.  
  31. HTTPReadPostValue((BYTE*)jsonData, sizeof(jsonData));
  32.  
  33. JsonParse_t parseTable[] =
  34. {
  35.     {".login",      JSON_STRING,    courierId,      sizeof(courierId)},
  36.     {".password",   JSON_STRING,    password,       sizeof(password)},
  37.     {".uuid",       JSON_STRING,    sessionuuid,    sizeof(sessionuuid)},
  38.     {NULL,          JSON_NONE,      NULL,           0}
  39. }
  40.  
  41. JsonParse(json, sizeof(json), parseTable);
  42.  
  43.  
  44. // Użycie pojedynczych funkcji
  45.  
  46. char json[HTTP_RESPONSE_BUFFER_SIZE];
  47. char courierId[COURIER_ID_LEN + 1];
  48. char password[MAX_PASSWORD_LEN_ASCI_MD5 + 1];
  49. char sessionuuid[RAPI_MAX_UUID_LEN + 1];
  50.  
  51. HTTPReadPostValue((BYTE*)jsonData, sizeof(jsonData));
  52.  
  53. JsonGetElement(json, sizeof(json), JSON_STRING, courierId, sizeof(courierId),     ".login");
  54. JsonGetElement(json, sizeof(json), JSON_STRING, password, sizeof(password),       ".password");
  55. JsonGetElement(json, sizeof(json), JSON_STRING, sessionuuid, sizeof(sessionuuid), ".uuid");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement