jsmn_furi.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * MIT License
  3. *
  4. * Copyright (c) 2010 Serge Zaitsev
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * [License text continues...]
  14. */
  15. #ifndef JSMN_FURI_H
  16. #define JSMN_FURI_H
  17. #include <jsmn/jsmn_h.h>
  18. #ifdef __cplusplus
  19. extern "C"
  20. {
  21. #endif
  22. #ifdef JSMN_STATIC
  23. #define JSMN_API static
  24. #else
  25. #define JSMN_API extern
  26. #endif
  27. JSMN_API void jsmn_init_furi(jsmn_parser *parser);
  28. JSMN_API int jsmn_parse_furi(jsmn_parser *parser, const FuriString *js,
  29. jsmntok_t *tokens, const unsigned int num_tokens);
  30. #ifndef JSMN_HEADER
  31. /* Implementation in jsmn_furi.c */
  32. #endif /* JSMN_HEADER */
  33. #ifdef __cplusplus
  34. }
  35. #endif
  36. #endif /* JSMN_FURI_H */
  37. #ifndef JB_JSMN_FURI_EDIT
  38. #define JB_JSMN_FURI_EDIT
  39. // Helper function to create a JSON object
  40. FuriString *get_json_furi(const FuriString *key, const FuriString *value);
  41. // Updated signatures to accept const char* key
  42. FuriString *get_json_value_furi(const char *key, const FuriString *json_data);
  43. FuriString *get_json_array_value_furi(const char *key, uint32_t index, const FuriString *json_data);
  44. FuriString **get_json_array_values_furi(const char *key, const FuriString *json_data, int *num_values);
  45. uint32_t json_token_count_furi(const FuriString *json);
  46. /* Example usage:
  47. char *json = "{\"key1\":\"value1\",\"key2\":\"value2\"}";
  48. FuriString *json_data = char_to_furi_string(json);
  49. if (!json_data)
  50. {
  51. FURI_LOG_E(TAG, "Failed to allocate FuriString");
  52. return -1;
  53. }
  54. FuriString *value = get_json_value_furi("key1", json_data, json_token_count_furi(json_data));
  55. if (value)
  56. {
  57. FURI_LOG_I(TAG, "Value: %s", furi_string_get_cstr(value));
  58. furi_string_free(value);
  59. }
  60. furi_string_free(json_data);
  61. */
  62. #endif /* JB_JSMN_EDIT */