Open Witexp opened 3 years ago
Good day. Now data is sent as an array of objects, often servers do not want to work with this format and you need to wrap the array in an object.
I suggest adding a parameter for the component - httpTemplateRoot: ‘data’
For the format of the sent data to be an Object Example: { data: [ { lat: '@latitude',lon: '@longitude', dt: '@time' }, { lat: '@latitude',lon: '@longitude', dt: '@time' }, { lat: '@latitude',lon: '@longitude', dt: '@time' }, ] } Now I solved this problem by changing the code for sending online in the file - PostLocatiionTask JSONArray jsonLocations = new JSONArray(); JSONObject jsonObjectLocation = new JSONObject(); // added
jsonLocations.put(mConfig.getTemplate().locationToJson(location));
jsonObjectLocation.put("data",jsonLocations); // added
responseCode = HttpPostService.postJSON(url, jsonObjectLocation, mConfig.getHttpHeaders()); // changed from jsonLocations to jsonObjectLocation
I also made corrections in the formation of data for sending with forceSync in the file - BatchManager
writer = new LocationWriter(fs, template); writer.beginObject(); // added writer.name("data"); // addedо writer.beginArray(); while (cursor.moveToNext()) { BackgroundLocation location = BackgroundLocation.fromCursor(cursor); writer.write(location); } writer.endArray(); writer.endObject(); // added writer.close(); fs.close();
For this, I also added the beginObject and endObject methods in the LocationWriter class.
But all my changes will be gone when I update or if I want to clean up node_modules I really look forward to your help in adding this parameter - httpTemplateRoot
Good day I managed to add a parameter for the component myself - httpTemplateRoot And the data to send can be of the form - { httpTemplateRoot: [ { lat: '@latitude',lon: '@longitude', dt: '@time' }, { lat: '@latitude',lon: '@longitude', dt: '@time' }, { lat: '@latitude',lon: '@longitude', dt: '@time' }, ] }
If you do not specify it, then the data is sent in the old way as an array - [ { lat: '@latitude',lon: '@longitude', dt: '@time' }, { lat: '@latitude',lon: '@longitude', dt: '@time' }, { lat: '@latitude',lon: '@longitude', dt: '@time' }, ]
I have done some refinement for both a single online submission and a bulk submission using forceSync ()
May I suggest these add-ons for a component of your component? How can I best provide them to you? Pull requests?
Plugin version: 0.6.3
Platform: Android
OS version: Android 10
Device manufacturer and model:
Running in Simulator:
React Native version: 0.63.2
Plugin configuration options:
At the moment, the application sends data in the form of an array, but not all servers can accept this data format. Is it possible to wrap this array in an object? Original - [{ "lat": '@latitude', "lon": '@longitude', "dt": '@time' }] Needed - {"data": [{ "lat": '@latitude', "lon": '@longitude', "dt": '@time' }] }