HI,
I'm running into an issue using miva_json_decode(). It looks like there are <br> tags inside of some of the text description of a paged JSON response I'm trying to process. It looks like miva attempts re-evaluate the JSON 3 times, then it moves on. I can see that, because it's writing the contents of the response to a file, and I see duplicate entries prior to hitting a problematic json string. It doesn't give up, but it does seem to be reprocessing the request.
Is there anything I can use to debug what's going on? I saw there's miva_json_decode_last_error() . But I'm not sure how I'd use that.
Is there a way to pre-process the JSON response and remove the <br.> tags?
Here's the code as is:
<mvt:comment>Start making requests</mvt:comment>
<mvt:assign name="g.api_request" value="'https://api.resellerratings.com/v1/product/reviews/full.json?sku=' $ g.code $ '&per_page=100' $ '&page=1'" />
<mvt:call action="g.api_request" method="'GET'" headers="'Authorization:Bearer ' $g.rr_token $ asciichar( 13 ) $ asciichar( 10 )">
<mvt:comment>Turn the JSON response into a miva structure</mvt:comment>
<mvt:assign name="l.success" value="miva_json_decode( s.callvalue, l.settings:review_data)" />
<mvt:comment>The first request sets the context for how many pages we have, it's page 1</mvt:comment>
<mvt:assign name="g.rr_rating_count" value="l.settings:review_data:data:rating:count" />
<mvt:assign name="g.rr_rating_score" value="rnd(l.settings:review_data:data:rating:scor e, 2)" />
<mvt:comment>Store the rating and review count in custom fields</mvt:comment>
<mvt:item name="customfields" param="Write_Product_Code( g.code, 'reviewcount', g.rr_rating_count )" />
<mvt:item name="customfields" param="Write_Product_Code( g.code, 'reviewstars', g.rr_rating_score )" />
<mvt:assign name="g.rr_review_user" value="l.settings:review_data:data:pagedReviews:da ta:author:username" />
<mvt:assign name="g.current_page" value="1" />
<mvt:assign name="g.total_pages" value="l.settings:review_data:data:pagedReviews:me ta:pagination:total_pages" />
<mvt:assign name="g.results" value="'<ul>' $ asciichar( 13 ) $ asciichar( 10 )" />
<mvt:comment>the end of the first call</mvt:comment>
</mvt:call>
<mvt:while expr="g.current_page LE g.total_pages">
<mvt:assign name="g.api_request" value="'https://api.resellerratings.com/v1/product/reviews/full.json?sku=' $ g.code $ '&per_page=100' $ '&page=' $ g.current_page" />
<mvt:call action="g.api_request" method="'GET'" headers="'Authorization:Bearer ' $g.rr_token $ asciichar( 13 ) $ asciichar( 10 )">
<mvt:assign name="l.success" value="miva_json_decode(miva_html_strip( s.callvalue),''), l.settings:review_data)" />
<mvt:assign name="g.rr_rating_count" value="l.settings:review_data:data:rating:count" />
<mvt:assign name="g.rr_rating_score" value="rnd(l.settings:review_data:data:rating:scor e, 2)" />
<mvt:foreach iterator="reviews" array="review_data:data:pagedReviews:data">
<mvt:comment>Do stuff with results, just getting the review users name here</mvt:comment>
<mvt:assign name="g.rr_review_user" value="l.settings:reviews:author:username" />
<mvt:assign name="g.results" value="g.results $ '<li>' $ g.rr_review_user $ '</li>' $ asciichar( 13 ) $ asciichar( 10 )" />
</mvt:foreach>
</mvt:call>
<mvt:assign name="g.current_page" value="g.current_page + 1" />
</mvt:while>
Example of bad JSON:
{
"id": 505117,
"author": {
"username": "Victor R F",
"location": null
},
"date": "2016-09-27 23:41:23",
"title": "This product is really good. Every CPAP user should have one.",
"text": "I normally do not write reviews. Don't like nor want to. Will make an exception here. It woks as described, is easy to install and it really takes care of the cleaning and bacterial issues a normal CPAP machine has. I had certain respiratory problems before I used this machine, in spite of hand washing the mask every day and soaking the rest of the system in water and vinegar for 12 hours plus once every 3 weeks. Those issues are now gone completely. <br /><br />The unpleasant smell that is present after the use of the system and that some reviewers complain about, does disappear by turning it on a few times for a few minutes after the daily cleaning. One of those purchases that is worth every penny paid, in spite of the price. ",
"rating": {
"score": 5,
"min": 0,
"max": 5
},
"user_recommend": null,
"reply": {
"text": null,
"date": null,
"vote_yes": 0,
"vote_no": 0
}
}
Any help greatly appreciated.
Paul
I'm running into an issue using miva_json_decode(). It looks like there are <br> tags inside of some of the text description of a paged JSON response I'm trying to process. It looks like miva attempts re-evaluate the JSON 3 times, then it moves on. I can see that, because it's writing the contents of the response to a file, and I see duplicate entries prior to hitting a problematic json string. It doesn't give up, but it does seem to be reprocessing the request.
Is there anything I can use to debug what's going on? I saw there's miva_json_decode_last_error() . But I'm not sure how I'd use that.
Is there a way to pre-process the JSON response and remove the <br.> tags?
Here's the code as is:
<mvt:comment>Start making requests</mvt:comment>
<mvt:assign name="g.api_request" value="'https://api.resellerratings.com/v1/product/reviews/full.json?sku=' $ g.code $ '&per_page=100' $ '&page=1'" />
<mvt:call action="g.api_request" method="'GET'" headers="'Authorization:Bearer ' $g.rr_token $ asciichar( 13 ) $ asciichar( 10 )">
<mvt:comment>Turn the JSON response into a miva structure</mvt:comment>
<mvt:assign name="l.success" value="miva_json_decode( s.callvalue, l.settings:review_data)" />
<mvt:comment>The first request sets the context for how many pages we have, it's page 1</mvt:comment>
<mvt:assign name="g.rr_rating_count" value="l.settings:review_data:data:rating:count" />
<mvt:assign name="g.rr_rating_score" value="rnd(l.settings:review_data:data:rating:scor e, 2)" />
<mvt:comment>Store the rating and review count in custom fields</mvt:comment>
<mvt:item name="customfields" param="Write_Product_Code( g.code, 'reviewcount', g.rr_rating_count )" />
<mvt:item name="customfields" param="Write_Product_Code( g.code, 'reviewstars', g.rr_rating_score )" />
<mvt:assign name="g.rr_review_user" value="l.settings:review_data:data:pagedReviews:da ta:author:username" />
<mvt:assign name="g.current_page" value="1" />
<mvt:assign name="g.total_pages" value="l.settings:review_data:data:pagedReviews:me ta:pagination:total_pages" />
<mvt:assign name="g.results" value="'<ul>' $ asciichar( 13 ) $ asciichar( 10 )" />
<mvt:comment>the end of the first call</mvt:comment>
</mvt:call>
<mvt:while expr="g.current_page LE g.total_pages">
<mvt:assign name="g.api_request" value="'https://api.resellerratings.com/v1/product/reviews/full.json?sku=' $ g.code $ '&per_page=100' $ '&page=' $ g.current_page" />
<mvt:call action="g.api_request" method="'GET'" headers="'Authorization:Bearer ' $g.rr_token $ asciichar( 13 ) $ asciichar( 10 )">
<mvt:assign name="l.success" value="miva_json_decode(miva_html_strip( s.callvalue),''), l.settings:review_data)" />
<mvt:assign name="g.rr_rating_count" value="l.settings:review_data:data:rating:count" />
<mvt:assign name="g.rr_rating_score" value="rnd(l.settings:review_data:data:rating:scor e, 2)" />
<mvt:foreach iterator="reviews" array="review_data:data:pagedReviews:data">
<mvt:comment>Do stuff with results, just getting the review users name here</mvt:comment>
<mvt:assign name="g.rr_review_user" value="l.settings:reviews:author:username" />
<mvt:assign name="g.results" value="g.results $ '<li>' $ g.rr_review_user $ '</li>' $ asciichar( 13 ) $ asciichar( 10 )" />
</mvt:foreach>
</mvt:call>
<mvt:assign name="g.current_page" value="g.current_page + 1" />
</mvt:while>
Example of bad JSON:
{
"id": 505117,
"author": {
"username": "Victor R F",
"location": null
},
"date": "2016-09-27 23:41:23",
"title": "This product is really good. Every CPAP user should have one.",
"text": "I normally do not write reviews. Don't like nor want to. Will make an exception here. It woks as described, is easy to install and it really takes care of the cleaning and bacterial issues a normal CPAP machine has. I had certain respiratory problems before I used this machine, in spite of hand washing the mask every day and soaking the rest of the system in water and vinegar for 12 hours plus once every 3 weeks. Those issues are now gone completely. <br /><br />The unpleasant smell that is present after the use of the system and that some reviewers complain about, does disappear by turning it on a few times for a few minutes after the daily cleaning. One of those purchases that is worth every penny paid, in spite of the price. ",
"rating": {
"score": 5,
"min": 0,
"max": 5
},
"user_recommend": null,
"reply": {
"text": null,
"date": null,
"vote_yes": 0,
"vote_no": 0
}
}
Any help greatly appreciated.
Paul
Comment