0

I'm trying to send some data through POST request to my server. I'm using JSONObject to send the data. This is the structure of my JSONObject

{
   "P_ID": "1000000",
   "P_Details": [
              {
                 "Day": "14Mar19",
                 "DayMS": "1552510800000",
                 "items": [
                       {
                           "productID": "1000003"
                       },
                       {
                           "productID": "1000004"
                       },
                       {
                           "productID": "1000005"
                       }
                 ] 
              },
              {
                 "Day": "15Mar19",
                 "DayMS": "1558510800000",
                 "items": [
                     {
                          "productID": "1000003"
                     },
                     {
                          "productID": "1000004"
                     },
                     {
                          "productID": "1000005"
                     }
               ]
            }
   ]
}

Now, this is a sample data for two days only.

In the end, I'll have data for 24 to 30 days and it'll be a huge JSONObject.

I've logged the complete JSONObject in my application before sending it to the server and I noticed that after 10 12 days data, the JSONObject.toString() isn't printing the complete values and the object is broken, it will be something like this.

{"P_ID":"1000000","P_Details":[{"Day":"14Mar19","DayMS":"1552510800000","items":[{"pr_ID":"1000000"},{"pr_ID":"1000001"},{"pr_ID":"1000002"},{"pr_ID":"1000003"},{"pr_ID":"1000004"},{"pr_ID":"1000005"}]},{"Day":"14Mar19","DayMS":"155251080

i've checked the character count and when it reaches 4051 lenght, it stops printing.

Now FIRST whats the issue here? Is there some characters Lenght limit for JSONObject or JSONArray because I've read these Q&A for String Length and my JSONObject.toString is nowhere near this limit.

Secondly, Should I actually create a JSONObject this big and send it through the mobile application?

PS. I've been trying to shrink this JSON Object but this is the bare minimum and maybe I'll have to add some more details along with productID field.

Joe
  • 173
  • 1
  • 15
  • How are you printing? The logger/console is probably the problem IMO, rather than the `toString()` method being broken. – Tim Biegeleisen Mar 14 '19 at 11:18
  • @TimBiegeleisen yes i'm using Logger for printing `Log.e("Object -> ", planObject.toJSON().toString());` .. Using Log.e just to make it standout in all the white lines. So what `The logger/console is probably the problem IMO, rather than the toString() ` means? my object is not broken and if I send it to the server it'll be a complete object? – Joe Mar 14 '19 at 11:20
  • I think the duplicate link covers your question. It offers two solutions, including breaking the line across multiple lines, and also using a different logger. – Tim Biegeleisen Mar 14 '19 at 11:24

0 Answers0