String in JSON format does not correctly... sometimes

I use the following (in collaboration with HttpConnectionFactory) to retrieve an our API JSON array:

public class LocationAPI {
    public static String getHttpResponse(String url){
        HttpConnectionFactory connfac = null;
        HttpConnection conn = null;
        DataInputStream ds = null;
        String response = null;
        try {
            connfac = new HttpConnectionFactory(url);
            conn = connfac.getNextConnection();

            if(conn.getResponseCode() == HttpConnection.HTTP_OK){
                ds = conn.openDataInputStream();
                byte[] data = new byte[ds.available()];
                ds.read(data);
                response = new String(data);
            }else{
                //http error response code handling
            }

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return response;
    }
}

The API returns something in the sense of the following:

{
    "data": [
        {
            "city": "Des Moines",
            "business_logo_url": null,
            "name": "LOUIES FLOOR COVERING INC",
            "phone": "515-243-8608",
            "icon_url": "/site_media/categoryicons/Shopping.png",
            "zipcode": "50312",
            "special_id": null,
            "state": "IA",
            "street": "2709 Ingersoll Ave",
            "special": null,
            "lat": 41.585709999999999,
            "lng": -93.653125000000003,
            "id": 136982,
            "website_url": null
        }
    ],
    "pages": 1,
    "page": 1
}

Depending on the situation, the query could return to what any one place 50 locations. Then I am parsing out them with the following:

try {
            JSONObject responseObject = new JSONObject(response);
            JSONArray responseArray = responseObject.getJSONArray("data");
            JSONObject itemObject = responseArray.getJSONObject(0);

            responseCity = itemObject.optString("city");
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

If the answer is short enough (I tested it with one place, still trying to find a query which returns both), it works fine. If he shoots Max (50 places), it-error "org.json.me.JSONException: missing value.» 829 character of ".". When I walked through it, I took a glance at the string and it seems to download the part of the answer. Any suggestions as to what I'm missing here?

Have you tried to hit the API in a browser to see if your server is truncating the answer? In addition, you can try to use

response = new String(IOUtilities.streamToBytes(ds);

in case the length of the response of statement is not ds.available (), but everything that is currently available for reading (probably the case).

Tags: BlackBerry Developers

Similar Questions

  • I have an index page that does not correctly load the css and css works on all other pages of the site.

    http://www.boulderridgecondos.com/ does not correctly load the css, but all other pages of the site loading the css correctly. There is nothing (that I can identify) between pages.
    http://www.boulderridgecondos.com/news.htm

    I guess something is wrong in the css, I inherited this site and have exceeded the css but can't find a problem that would cause this to happen.

    Any help or suggestion looking for something would be appreciated.

    This page is saved in UTF-16 format (Content-Type: text/html (UTF-16 BOM, litte-endian)) in your text editor. The CSS file is sent as ISO-8859-1. Firefox fun to see all the files in the same encoding. The other pages are send as ISO-8859-1 and so use the CSS file. You will need to re - save this page as ISO-8859-1 and download the corrected version.

  • HP 8600: HP 8600 does not correct tray

    Hello. I'm having trouble with my HP 8600 is not pulling from the correct tray. This is a recent problem that everything was working properly until a few days ago. I have an accessory to two tray with tray #1 used for special dimensions (photos and envelopes) and standard #2 to 8.5X11paper tray.  I have the default to tray #2 and locked bin #1 in my settings (#1 on the top tray, tray # 2 down). However, when I send a print job for normal letter format, he tries to send the job to use the Tray #1. I can get around this by changing the trays, but it is a real pain and much slower. I checked all software and firmware is up to date. I hope someone has a solution for this problem.

    Hi @Desertboy,

    Thank you for joining the HP Forums!

    I have seen your post on how your printer HP Officejet pro 8600 does not correct status bar. I'm happy to help with this problem!

    Follow these steps to change the print settings by default for all printing from the desktop of Windows 8.

    1. Right click or touch and hold the bottom left of the screen to open the menu. In the menu, click or tap on the Control Panel, then click on or type printers and display devices.

    2. Right click or tap and hold the icon of the printer () for your printer, and then click or tap Print Preferences.

    3. Select your new default print settings, and then click or tap on OK.

    Source: change of print settings (Windows 8).

    I would use these settings to set the default to tray 2 for plain paper. So if you want to print to Tray 1, you can change the settings manually. Or, you can add the same printer again in the devices Panel and printers and together this is the default for Tray 1 for specialty paper and rename it to 8600 (Tray 1) as an example.

    If this, or one of the posts on this thread, helped you to solve the problem, please click on accept as Solution on the message. To show you 'like', or that they are grateful for my post, please click the thumbs upwards below. If there is anything else I can do to help, please don't forget to let me know!

    I hope these settings help!

  • Smart card reader does not correctly connect once the virtual machine is restored from sleep using the vmrum controls

    Smart card reader does not correctly connect once the virtual machine is restored from sleep using the vmrum controls

    Scenario is,

    1. smart card reader is connected to the VM with card inserted in

    2 initiate a prompt suspension of the VM toolbar

    3. now to resume the virtual machine by using vmrun command into the host machine

    WS t vmrun start xxx.vmx

    Now, the recovery of VM but the smart card reader that was previously connected does not work properly in VM that is to say, sometimes after CV chip card reader driver is uninstalling and a few other times, chip connected to the drive is not available on a virtual computer

    My requirement is after power, smart card reader can stay connected to the virtual computer with the already installed driver and the smart card.

    Kindly help with this problem.

    Host operating system: Victoire 2012 R2

    The VM OS: win 10 x 64

    Thank you!!

    Dear all,

    I had a work around for this problem. By adding "usb.autoConnect.device0 ="0xVID:0xPID"" this statement to the VMX file, solves this problem, that is, whenever the VM is wake-up by clicking on the link CV or using vmrun commands, it connects the unit in question automatically and it is charging correctly with his driver. Obtaining smart card detected after sleep\hibernate with no problems.

    VID & PID is respective ID of the device that can be seen in the properties of the Device Manager "Device Instance path".

    For more information about this, visit VMware KB: automatic connection of USB devices to the virtual machine power on

    ~ Surendra

  • Round trip for formatting does not

    My problem is that when I open an XML file in FrameMaker, the formatting does not use my application that I put in place. I don't know where this is controlled.

    That's what I did. I made a copy of the folder Structure\xml\DITA to create Structure\xml\MyDITA. I converted my documents to DITA and updated the application model and ESD (formatting only) in the MyDITA folder. I did not the DTD.

    When I save my file in XML format I get no errors, but when I open the XML file on the FM band, the formatting does not my model of the MyDITA.

    When I open the selected file XML in FM and StructureTools > structured Application set and it has the value DITA_1.2_topic. When I put in MyDITA has no effect on the formatting.

    What is control what application to use when the XML file is opened? I have a custom XML application that works very well. The Doctype in my XML file is:

    <! Topic DOCTYPE PUBLIC "-//OASIS//DTD DITA topic / / IN" "topic.dtd".

    I hope it's an easy question to answer. Thank you!

    Gman

    HEY gman...

    Using the command set the structured Application is not "permanent", when used on an XML file. You can use it to check the application currently assigned to a file, but don't bother setting it.

    You must assign the appropriate on the open file application. This is done by ensuring that you have a valid structure for your application application definition (in the definition of Application Structure file) AND ensuring that this application definition is correctly configured in the dialog box Options of DITA (section mapping of the application). It seems that the DITA 1.2 app is still selected in the Options.

    In Options of DITA, select the "DITA v1.1" option, then click the button «...» "to the right of the associated drop-down list. In the mapping Manager dialog box, choose new mapping in the mapping of tag list, give it a name ("MyDITA 1.1 Mapping') and choose APP_MAPPING_DITA_1.1 from the mapping Type list. Now, in the mapping Manager dialog box, enter the doctype for your app... "section" (according to your example), then enter the name of the "MyDITA" application, then select the "CATEGORY" Type (in this case). Now, choose Add/Edit. If your application supports other types of items, you will need to add them to the list of mapping. When you are done click OK. Options of DITA, you can now select your application mapping in the list (or it may already be selected).

    In theory it should "work"... you will need to exit and restart FM to do properly defined.

    Yes... It is not easy or straight forward, and the docs are pretty weak.

    No pressure... but have you looked in (or heard of) DITA-FMx? It simplifies the whole process considerably (although the application development is still a bit of a learning curve) and makes DITA book.

    http://leximation.com/DITA-FMX/

    See you soon,.

    .. .Scott

    Scott Prentice

    Leximation, Inc..

    www.leximation.com

  • with firefox 43 yahoo and yahoo mail doesn't work does not correctly

    With the help of win 7 and firefox 43.0.1, I have 4 computers and now all have problems with yahoo and yahoo mail doesn't work does not correctly. Loading sites, but most of the features are missing and clicking on what whether changes to the lists of text. I have disabled flash / anti-spam etc., cleared cookies and cache and even firefox loaded down once again and have upgraded, no help. I'm forced to use IE now.

    I tried Yahoo support, they said try Firefox... In any case, it's Firefox and I found a solution using the 'Refresh Firefox' button. Whatever the problem was fixed on two of my computers so far. Got to update my setting again but it's 10 m, compared to the 10 hours I spent trying all that is nothing.

    Thanks for the help!

  • disc eject does not correctly persist

    I get several error messages that my external hard drive was not ejected correctly. I ejected it, turned off, unplugged and then reverse the process. Whenever my screen locks when I open it there are several messages not eject disks does not correctly.

    Restart your Mac, and then drag the disc on the desktop for the external drive to the trash.

  • I created a custom and registered with a specific name date format. However, when I open a new worksheet, my saved format does not display in the menu drop-down? Am hoping that I don't need to create the same format for each new sheet?

    I created a custom and registered with a specific name date format. However, when I open a new worksheet, my saved format does not appear in the menu drop-down? Am hoping that I don't need to create the same format for each new sheet?

    You must save the spreadsheet containing the new date as a model format and use this custom template for each new spreadsheet where you want that this date format personalized at your disposal.

  • HP jet 7500 a desktop: office jet 7500 a print does not correctly

    Hello
    After you run the print doctor, cleaning and aligning the print heads that it is still print does not correctly. the first page comes out perfect so the print quality gets worse, with bits wilted and things missing. just print a page of print quality and black looks at all and the first steps of pink and yellow are strong, blue stripes and then 2nd very faded pink and yellow bar.
    any ideas?

    Hey watch this video of HP, how do I solve this https://www.youtube.com/watch?v=c422Q-EhMXI if this fixed your problem can you give me a point of congratulations. Thank you

  • Satellite A300 - keyboard does not work sometimes

    Hello

    the boot of my Toshiba Satellite A300 computer laptop keyboard doesn't work sometimes?

    After a reboot, everything is ok!

    Anyone know why the keyboard does not work sometimes?
    Greetings

    On this virtual path, it is not easy to give you a precise answer, especially if it happens sometimes and I think that you need professional help with this.

    There may be a connection between the keyboard and the motherboard problem.
    I fear, we can only speculate that the problem can be m.

  • Satellite A200 does not correctly reduce or increase the volume

    Hello

    Our Satellite A200 is having problems with its Volume control wheel.
    If I turn the wheel (on the left or in the past), it does not correctly to reduce or increase the volume level.
    He jumps rather the volume level in seemingly random directions (with a preference for the volume).
    Turn the wheel slowly improves responsiveness a little, but it remains quite impossible to increase or decrease the volume control that to be.

    BTW, I am well aware that the volume control wheel is a wheel of puls-encoder rather than ye olde potentiometer.

    -Can anyone you tell me where I can find the configuration that is responsible for this Volume control wheel?
    -Which driver/firmware is attached to the order of the volume control?
    -How can I determine if this is a hardware or software problem?

    Advice would be welcome.

    Stephan

    Hello

    There is no software or hardware problem.
    It is a new generation of volume control.

    First of all there is no mechanical limit turning right or left.
    In addition, this volume controller works a little different than the old volume controllers. The volume can be increased and decreased using the fixed rate

    By the way;
    > Can someone tell me where I can find the configuration that is responsible for this Volume control wheel?
    You can change the volume as in the sound settings that could be found in the control panel.
    > Which driver/firmware is attached to the order of the volume control?
    Audio driver controls the volume controller.
    > How can I determine if this is a hardware or software problem?
    There is no problem

  • error code 259 does not correctly updated to sp62736.

    I have a Hp Pavilion 500-141ea im trying to update the IDT audio driver for windows 8, I supported SP sp62736, it passes through the installation procedure, then it stops and comes up with this error code 259 does not correctly updated, I even disabled etc still the same antivirus software.

    Any idea?

    Hi Apache1968,

    If everything works at the moment, with the exception of downloading then I would leave it as it is. The whole "don't mess with what works" thing.

    Thank you

  • Why is one of my 4 5893 Modules doesn't work does not correctly?

    Hello

    This is the configuration of my HW and SW:

    LabView 2013 SP1

    1 x cRIO 9076

    4 x NI 9853 CAN Modules

    CAN0 - 1000 Kbps, entry timeout = 0, OutputTimeOut = 10000, Module clock: 20 MHz

    CAN1 - 500 Kbps, entry timeout = 0, OutputTimeOut = 10000, Module clock: 20 MHz

    I worked on a program for a test system, where each Module 9853 control two devices (CAN0 and CAN1), the same type of systems is controlled by other 9853 3 Modules in parallel.

    So basically, I use exactly the same functions for each module. So far, everything has worked correctly on module 1, but now that I started to test all other modules I have the problem that Module 3/CAN0 does not correctly read the information.

    While watching the FPGA façade, I see that each 10000ms one value is read, but only on that ONE module (frames are sent every 1ms from my unit)

    I tested the HW itself using the included examples and it works correctly, the only difference is that the example used only 2 Modules, one to send data and the other to receive it.

    I included my FPGA program as an image, I really don't think there is a problem with my RT SW, because all the other modules are working properly. Basically, my SW FPGA bed CAN Modules and puts the information in a FIFO, if there is an error (no information), it will make a loop once more and check again.

    Thanks for your help

    I solved the problem, it was an error of configuration on my side.

    The entry for Module3 CAN1 time-out was set up NOT as 0ms and 10000ms as I thought! , so that was my reading for DUT3 loop run only every 10000ms.

  • Update KB976902 now the mouse doesn't work does not correctly

    I had the KB976902 recently updated on 2 of the 3 computers and 2 who got now have a mouse that does not correctly.  The computer number 3 does not have the update and still works fine.  All three are almost identical hardware and software and have legitimate versions of windows 7.

    The problem of the mouse made play almost almost impossible. Left click crashes, lag mouse click one or two times when I I try to do a restore from the left eventually drag a shortcut of the thing, I clicked on and don't know how or why.

    I did a restore on a single computer, but it did not help.

    Norton and McAfee applications are notorious for not to uninstall (or upgraded) themselves. Since you are not sure, I'll have to have executed two removal on all of the computers in question tools.

    NB: If a step said to reboot, reboot!

    1. download the Norton Removal Tool, save it to your desktop: ftp://ftp.symantec.com/public/english_us_canada/removal_tools/Norton_Removal_Tool.exe

    1B. download the tool McAfee Consumer Product Removal, save it to your desktop: http://download.mcafee.com/products/licensed/cust_support_patches/MCPR.exe

    2. close all open applications (that is, anything with an icon on the taskbar).

    3. right click on the file saved in # 1 above and select run as administrator to run the utility. DO TAP not your keyboard until the race ends, then restart.

    3B. right-click on the file saved in # 1 b above and select run as administrator to run the utility. DO TAP not your keyboard until the race ends, then reboot again.

    4 reset the IE8 advanced settings by http://windows.microsoft.com/en-US/windows7/Reset-Internet-Explorer-settings

    5. open Internet Explorer 32-bit (only!) to http://support.microsoft.com/kb/971058 & run it in DEFAULT and modes difficulty then AGGRESSIVE. [1]

    6. restart a last time & test.

    ~~~~~~~~~~~~~~~~~~~~~~~~
    [1] full Disclosure: the difficulty operating in AGGRESSIVE mode will remove your update history but not the list of installed updates.

    ~ Robear Dyer (PA Bear) ~ MS MVP (that is to say, mail, security, Windows & Update Services) since 2002 ~ WARNING: MS MVPs represent or work for Microsoft

  • Acer site does not correctly display the specification.

    Acer site does not correctly display the specification.

    Example when you click on the link on M5 Explorer - 581 T-6405 please as to the specification of the model of S7-191-6447. Please check

    Thank you bring to our attention. We will ensure that it is transmitted.

Maybe you are looking for

  • Batch conversion metric, temperatures, etc. ?

    Imagine a data column in a Numbers spreadsheet, where each digit refers to feet. Is it possible to convert the entire column to a metric equivalent? And can we do the reverse - convert meters to feet? What conversion miles square kilometers square, c

  • La carte video card mother cupertino2

    See you soon! I ve got a HP Pavilion p6-2055sc with a motherboard cupertino2-H61-au-TX and processor i3 2120. I'm about to upgrade to a core i5 - 2500 k. I am also considering a new graphics/video card that is compatible with the motherboard. I don't

  • What is the resolution for USB-6210 for positive ranges of entry?

    Hello I use USB-6210 to sample different types of sensors and each has its own range of values. I have two questions: (a) what are the fixed beaches of USB-6210 where most suitable is chosen automatically depending on the settings of user intput scop

  • PCIe Bus error warning

    Hello need help with this error... You can find the error image to attach file... it's only happen when chart pantented is connected, it's all new alienware leptop 17 r3...

  • Connect pc with win 7 to an instrument THEN use the com port and the PPP protocol

    Dear all, I need to make a connecting series between a pc with win 7 and one instrument. To achieve this I have to use the com port and Protocol PPP. In win xp is possible but I'm not able to find the same in win7 concerning Diego