[Ethereum] How to concat a double quote into a string in Solidity

soliditystring

I am looking for a solution to concat double quotes ("") into a string in Solidity.

What I need looks like this:

'{"id":idHere,"Lname":lname,"Fname":fname}'

All I get is sth like '{\"id\":idHere,\"Lname\":lname,\"Fname\":fname}'

PS: idHere, lname and fname are variables not constant value.

Best Answer

There is a strConcat() function in the usingOraclize contract that you are most likely inheriting from. You could use it like this:

  function queryString(
    uint256 _dynamicVariable
  ) 
    internal
    returns (string)
  {
    return strConcat(
      apiPrefix, // https:// or something like that
      encryptedApiComponent, // my example encrypts the domain
      "}", // closing part of oraclize query
      uint2str(_dynamicVariable), // also from oraclize 
      apiSuffix
    );
  }