Tester
Tester

Reputation: 2967

Error reading JSON from URL

I am trying to read json into my C# application from a url. When I run the application I keep getting a error:

"Additional Text encountered after finished reading JSON content: {. Path ",line 2, position 667".

This is from this URL

I checked the page and the view source and can't seem to find the problem. How do I fix this?

The JSON is derived from a php array that is json encoded and echoed:

    $args = array( 'post_type' => 'product', 'posts_per_page' => 200, 'product_cat' => 'Alcopops' );

    $loop = new WP_Query( $args );

    while ( $loop->have_posts() ) : $loop->the_post(); 
    global $product; 
echo json_encode($product);

    endwhile; 


    wp_reset_query(); 

Upvotes: 0

Views: 429

Answers (2)

Martin Booth
Martin Booth

Reputation: 8595

That page doesn't contain valid json. Take a look at this:

"product_type":"simple"}{"id":246,"post":

there's no comma between } and {

Edit:

The problem is with your php, rather than the c#.

Try this:

$args = array( 'post_type' => 'product', 'posts_per_page' => 200, 'product_cat' => 'Alcopops' );
$loop = new WP_Query( $args );
echo json_encode($loop->get_posts());
wp_reset_query(); 

Upvotes: 2

Sirwan Afifi
Sirwan Afifi

Reputation: 10824

use WebClient :

var json = new WebClient().DownloadString("http://cbbnideas.com/brydens-website/products/?category=Alcopops");

Upvotes: 0

Related Questions