Removing double quotes from a string from JSON response in PHP

+1 vote

I am using this code that I got from git, and when I get the BlockChain API response while getting the address from the wallet, the address is enclosed in double quotes like below. 

"43Hua8Qz1dj82ddoyLBe448HAXShsuBCAp"

I want to remove these double quotes because it might create syntax errors. But I am not sure how to do it. Please help

This is the code I am using:

$resp = file_get_contents($blockchain_receive_root . "v2/receive?key=" . $my_api_key . "&gap_limit=".$gap_limit. "&callback=" . urlencode($callback_url) . "&xpub=" . $my_xpub);
$response = json_decode($resp);

print json_encode($response->address);

How to remove the quotes?

Sep 12, 2018 in Blockchain by slayer
• 29,370 points

edited Apr 24, 2019 by Omkar 45,140 views

Why are you using json_encode?

Hi @Himesh. I am just using the code that was available on git. Didn't add the line. I am new to Json so don't much.

3 answers to this question.

+2 votes
Best answer

Just remove the json_encode call, and it should work:

$resp = file_get_contents($blockchain_receive_root . "v2/receive?key=" . $my_api_key . "&gap_limit=".$gap_limit. "&callback=" . urlencode($callback_url) . "&xpub=" . $my_xpub);
$response = json_decode($resp);

print $response->address;
answered Sep 12, 2018 by digger
• 26,740 points

selected Apr 24, 2019 by Omkar

Hey, thanks for the solution. Can you please tell what json_encode does?

json_encode is a PHP function that is used to convert PHP objects to Json object. So when you use json_encode, the PHP object is getting converted to Json object and that's why you are seeing double quotes. 

0 votes

You are getting double quotes because the line json_encode is encoded it into an address and that's why you can double quotes when you print it. If you don't use the encoding, it should be fine. 

answered Apr 24, 2019 by Himesh
0 votes

You can use the replace method to replace the double quotes with nothing. Here's the code to do that. 

var test = "\"43Hua8Qz1dj82ddoyLBe448HAXShsuBCAp\"";
console.log(test);
console.log(test.replace(/\"/g, "")); 
answered Apr 24, 2019 by Birendra

Related Questions In Blockchain

0 votes
1 answer

Cant get a specific value in JSON/PHP

Convert the json-string to a php-array and ...READ MORE

answered Sep 11, 2018 in Blockchain by slayer
• 29,370 points
2,852 views
+1 vote
2 answers

How to return value from a chaincode in Hyperledger Fabric?

Hyperledger Fabric supports only 2 types of ...READ MORE

answered Jun 13, 2018 in Blockchain by Perry
• 17,100 points
2,929 views
0 votes
1 answer

obfuscating and deobfuscating a string in JavaScript

You can use btoa() and atob(). btoa() is like base64_encode() and atob() like base64_decode(). Here is an example: btoa('Some ...READ MORE

answered Aug 23, 2018 in Blockchain by slayer
• 29,370 points
1,283 views
0 votes
1 answer

var_dump of a JSON response returns NULL

You should be aware of the chances ...READ MORE

answered Aug 28, 2018 in Blockchain by digger
• 26,740 points
3,470 views
0 votes
1 answer

How do I add multiple recipients for transactions via Blockchain API?

Convert the recipes into JSON objects. x = ...READ MORE

answered Jul 6, 2018 in Blockchain by Perry
• 17,100 points
851 views
0 votes
1 answer

Send Payment error in Blockchain API

The following code should help: $address = null; try ...READ MORE

answered Jul 6, 2018 in Blockchain by Perry
• 17,100 points
1,739 views
0 votes
1 answer

Python request module for bitcoin json rpc

This should work: #!/usr/bin/env python import getpass import json import requests ...READ MORE

answered Aug 28, 2018 in Blockchain by digger
• 26,740 points
2,337 views
0 votes
0 answers

Blockchain.info wallet API callback

I am implementing blockchain.info wallet api to ...READ MORE

Jul 4, 2018 in Blockchain by sabby
• 4,390 points
859 views
0 votes
1 answer
0 votes
1 answer

How to use Proc/lamba returned from a method in Ruby?

You need to remove the colon: list.select(&valid_transaction) The & ...READ MORE

answered Aug 24, 2018 in Blockchain by digger
• 26,740 points
641 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP