However, things may not be as easy you can think of. The documentation given is still lack of information and there are not many solutions that can help you to solve your problem. One of it is Cannot parse JSON-encoded object value issue.
The error message you will get as example below
error": {
"statusCode": 400
"name": "Error"
"message": "Cannot parse JSON-encoded object value."
"stack": "Error: Cannot parse JSON-encoded object value. at Object.fromSloppyValue (D:\Project\loopback\touchpoint\node_modules\strong-remoting\lib\types\object.js:34:19) at HttpContext.buildArgs (D:\Project\loopback\touchpoint\node_modules\strong-remoting\lib\http-context.js:193:22) at new HttpContext (D:\Project\loopback\touchpoint\node_modules\strong-remoting\lib\http-context.js:59:20) at restStaticMethodHandler (D:\Project\loopback\touchpoint\node_modules\strong-remoting\lib\rest-adapter.js:485:15) at Layer.handle [as handle_request] (D:\Project\loopback\touchpoint\node_modules\express\lib\router\layer.js:95:5) at next (D:\Project\loopback\touchpoint\node_modules\express\lib\router\route.js:137:13) at Route.dispatch (D:\Project\loopback\touchpoint\node_modules\express\lib\router\route.js:112:3) at Layer.handle [as handle_request] (D:\Project\loopback\touchpoint\node_modules\express\lib\router\layer.js:95:5) at D:\Project\loopback\touchpoint\node_modules\express\lib\router\index.js:281:22 at Function.process_params (D:\Project\loopback\touchpoint\node_modules\express\lib\router\index.js:335:12) at next (D:\Project\loopback\touchpoint\node_modules\express\lib\router\index.js:275:10) at Function.handle (D:\Project\loopback\touchpoint\node_modules\express\lib\router\index.js:174:3) at router (D:\Project\loopback\touchpoint\node_modules\express\lib\router\index.js:47:12) at Layer.handle [as handle_request] (D:\Project\loopback\touchpoint\node_modules\express\lib\router\layer.js:95:5) at trim_prefix (D:\Project\loopback\touchpoint\node_modules\express\lib\router\index.js:317:13) at D:\Project\loopback\touchpoint\node_modules\express\lib\router\index.js:284:7"
How to solve this?
- Ensure that you run and test your parameter passing which should be in JSON format is valid. You may use online such as Jsonlint or any JSON validator available.
- If it is valid, then, ensure that all key and value is in open and close double quote - "key": "value". Do not use single quote 'key': 'value'
- Finally, if the above two is correct, encode some of your parameter; for instance, '%' shall be encoded to '%25'. Use online encoder to help you such as https://www.urlencoder.org/
The above solution only applicable if you implement method through http GET, POST, PATCH, etc request. It may not be applicable for other REST calling method.
#enjoycoding
2 comments:
Nice Information thank you for Sharing useful information. Great job.
Web developer Malaysia
Thanks for the info.
Good work.
Post a Comment