locked
c# I can not Parse JSON to string RRS feed

  • Question

  • User-1386290456 posted

    I have problem with my code. I don't know how to fix. I just want to get all title and gig_url from JSON url and write it to my arraylist. It showed error at: var obj = JObject.Parse(jsons);

    
    

     

    Thursday, May 12, 2016 2:58 PM

Answers

  • User-1386290456 posted

    It is Json format and my problem is solved. Close. :)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 13, 2016 4:21 AM

All replies

  • User753101303 posted

    Hi,

    So and have you just looked at the string found in jsons? Could it be that the string is entirely empty?

    Thursday, May 12, 2016 3:55 PM
  • User303363814 posted

    Set a breakpoint and look at the value of 'jsons'.

    You will see that it is unreadable.

    Try the url in your browser and open the developer tools.  There you will discover that the Content-Encoding is 'gzip'.

    To read and decompress at the same time you can derive your own class from WebClient like this

    class MyWebClient : WebClient
    {
    	protected override WebRequest GetWebRequest(Uri address)
    	{
    		HttpWebRequest request = base.GetWebRequest(address) as HttpWebRequest;
    		request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
    		return request;
    	}
    }
    

    Then change your code from

    using (var webClient = new System.Net.WebClient())

    to

    using (var webClient = new MyWebClient())

    Luke used the force - developers use the debugger.

    Friday, May 13, 2016 12:01 AM
  • User-1386290456 posted

    Hi you can see the raw data on json url when opened it..

    Friday, May 13, 2016 2:19 AM
  • User303363814 posted

    Use the debugger.

    Your browser does lots of things for you for free.  One of them is to unzip a gzipped response.

    Trust me - I have run your code, verified your problem, used the debugger to investigate the problem, examined the output from the web site using developer tools to see what is actually happening, written code to fix the problem, run the code, checked that it worked and then posted the solution here.

    You can argue with me or just use the working, tested solution that I have provided.  Your choice.

    Friday, May 13, 2016 2:27 AM
  • User-1386290456 posted

    Hi,

    I tried using it, but it does not works.

    Friday, May 13, 2016 2:29 AM
  • User-1386290456 posted

    The data I got does not like raw data on url

    So I think that is why I can not parse to Json. How can I solve it?
    Friday, May 13, 2016 2:33 AM
  • User303363814 posted

    tried using it, but it does not works.
    Cab you add a little detail to this?

    Friday, May 13, 2016 2:51 AM
  • User-1768369891 posted

    aheda4321

    So I think that is why I can not parse to Json. How can I solve it?

    Hi aheda,

       I think your json string which you want to be not in correct format if you want to check json format is vaild or not try this .

       http://json.parser.online.fr/

       or you can post code where you make json string may be there is problem. 

     when i try to convert it json take look...

    {
       "gigs":
            [
               {
    "title":"draw an Eye Catching Cartoon TShirt Design",
    "cached_slug":"draw-an-eye-catching-cartoon-tshirt-design",
    "status":"approved",
    "title_full":"draw an Eye Catching Cartoon TShirt Design",
    "duration":6,
    "price":"$5",
    "price_i":5,
    "rating":10,
    "rating_count":944,
    "is_featured":true,
    "gig_created":"2014-01-08T11:28:20.000-04:00",
    "gig_id":2539315,
    "gig_url":"/valiantgraphics/draw-an-eye-catching-cartoon-tshirt-design?context=adv.cat_3.subcat_154\u0026context_type=auto\u0026pos=1\u0026funnel=e3e9b4d8-0c4f-488d-bafa-8bc6049b682e"
    }
    ]
    }


     

     

    Friday, May 13, 2016 2:57 AM
  • User-1386290456 posted

    It is Json format and my problem is solved. Close. :)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 13, 2016 4:21 AM