locked
Json String limited to 2k characters ?

    Question

  • Hi there,

    I'm having trouble trying to parse some Json using this method :

    JsonValue^ jsonValue = JsonValue::Parse(String^ jsonSring);

    My problem is that the String value is limited to 2048 characters and my JSON string is about 50.000.

    There is no point using Json if the string type is that limited :/

    Any tips ?

    Wednesday, July 11, 2012 3:29 PM

Answers

All replies

  • I'll look into this today and post back as soon as I have more details.

    David Lamb

    Thursday, July 12, 2012 4:12 PM
    Moderator
  • I'm not encountering the size limitation you mentioned in the tests I've run through today. Could you paste the code that produces this problem? You can also email me a sample project if you like to:

    DavidLam AT Microsoft DOT com

    Thanks!


    David Lamb

    Thursday, July 12, 2012 7:28 PM
    Moderator
  • Nevermind, I think the limit is only applied when you declare a string  between the double quotes ( String^ myString = " myLongString" ) directly in the code ( 2.000 chars seems still a bit low to me :) ).

    I guess it should work saving the string through an HTML Request !

    Thanks again David, if you need any other informations, i would be glad to help you.

    Friday, July 13, 2012 3:10 PM
  • Ah, I wasn't trying to initialize a string in that manner. The only limit I could find that you should encounter is a compiler error C2026 which is not specific to Metro style apps. You may find using this initialization pattern allows for more characters than you are currently able to initialize. I was initializing the string with >10k characters so if you can only get 2k, contact me so I can look into your situation further.

    String^ s("AAAAAAAAAA");

    You may consider using another method of storing static strings this large if this is a common pattern in your app. 

    This //build/ talk demonstrates a few other ways to initialize and use strings as well:

    Tips and tricks for developing Metro style apps using C++

    TOOL-845T
    Speakers: Tarek Madkour

    Thanks!


    David Lamb


    Friday, July 13, 2012 10:18 PM
    Moderator
  • Uhmm just a side node, String^ s("AAAAAA"); is missing the "L" marker for unicode text. This statement would not compile, would it?
    Saturday, July 14, 2012 4:55 AM
  • Give it a try. The compiler knows that has to be Unicode and treats it as such.

    See http://msdn.microsoft.com/en-us/library/windows/apps/hh699879(v=vs.110).aspx

    --Rob

    Saturday, July 14, 2012 5:01 AM
    Owner
  • I am sure I tried it several times in the past. Or maybe I am mixing it up with char* s1 = "AAAAA"; String^ s2(s1); which does not work.
    Saturday, July 14, 2012 5:07 AM
  • Tried this way, still getting error C2026 :(

    I guess I'll have to find another way to store these data !

    Thanks again guys

    Monday, July 16, 2012 9:31 AM
  • @UbuW8 how are you receiving the string from the html request? What API are you using to fetch the html content?
    Monday, July 16, 2012 11:32 AM
  • I'm using IXMLHTTPRequest2 API
    Monday, July 16, 2012 2:03 PM
  • Take a look at http://sridharpoduri.com/2012/07/02/using-json-and-c-in-windows-8-apps/ and the corresponding LiveSDK project from GitHub. The sample from LiveSDK has an implementation of IXMLHttpRequest2 in conjunction with ISequentialStream interface.

    Essentially, you need to read the response in a loop until end of stream.  

    Hope this helps.

    Monday, July 16, 2012 2:39 PM
  • I'll look into this, thank you !
    Monday, July 16, 2012 2:44 PM
  • here is the GitHub project link https://github.com/liveservices/LiveSDK/tree/master/Samples/WindowsConsumerPreview/XAML/SkyPadCpp I forgot to add this to my previous reply. You have to modify the OnResponseReceived function in XHREvent.cpp to read the response in a loop.

    Monday, July 16, 2012 2:52 PM