Rectangle 27 1

A string in javascript is enclosed in '' or in "", but the example you gave as neither. If you are sure that quotation marks will not be part of the output, enclose @Html.Raw(...) with quotation marks. eg. LoadXMLString('RfqXmlData', '@Html.Raw(...)');

If the string output of @Html.Raw(...) contains single quotes, this would break tho.. you might want to replace "'" with "\'" as well in that case.

I actually thought of that right after I posted the question. I tried it with @Html.Raw("'" + Model.RfqXmlData.. + "'"). Your way is better, though.

asp.net - Javascript unexpected token '<' when loading XML from model ...

javascript asp.net xml asp.net-mvc razor
Rectangle 27 2

After trying to handle different cases (handling both stderr and stdout and not blocking any of these, terminate process after timeout, properly escaping slashes, quotation marks, special characters, spaces, .... ) I gave up and found Apache Commons Exec https://commons.apache.org/proper/commons-exec/tutorial.html that seems to be doing all these things pretty well.

I do recommend everyone who needs to invoke external process in java to use Apache Commons Exec library instead of reinventing it again.

Thank you very much. I was trying to execute wkhtmltopdf program with arguments using ProcessBuilder. It was ok in Windows but in the Linux server it failed and I wasn't not able to get the output with BufferedReader. However everything was easy with commons-exec and it worked fine in both operating systems.

java - How to redirect Process Builder's output to a string? - Stack O...

java stream processbuilder
Rectangle 27 0

Edited In case recursion was not the goal, here's an edited version that solves the issue and the quote escaping: Live on Coliru (or just source here)

Hmm. It looks like you might have been after a recursive attribute/rule:

typedef boost::make_recursive_variant<int, std::string, std::vector<boost::recursive_variant_> >::type Parameter;

Just in that case, here's a simple approach to generating that:

gen = int_ | string | gen % ", ";

Now, your title suggests that strings containing double-quotes should escape these. I suggest

str = '"' << *('\\' << char_('"') | char_) << '"';
gen = int_ | str | gen % ", ";

Now the following test cases

for (Parameter p : Parameters { 
        1, 
        "foo",
        Parameters { 1, "foo" },
        Parameters { 1, "escape: \"foo\"", Parameters { "2", "bar" } } 
   })
{
    std::cout << karma::format(gen, p) << '\n';
}
1
"foo"
1, "foo"
1, "escape: \"foo\"", "2", "bar"

If recursion is really a feature, you'd want to see the grouping of nested Parameter lists:

gen = int_ | str | '{' << gen % ", " << '}';
1
"foo"
{1, "foo"}
{1, "escape: \"foo\"", {"2", "bar"}}
#include <boost/variant.hpp>
#include <boost/spirit/include/karma.hpp>

namespace karma = boost::spirit::karma;
typedef boost::make_recursive_variant<int, std::string, std::vector<boost::recursive_variant_> >::type Parameter;
typedef std::vector<Parameter> Parameters;

int main()
{
    typedef boost::spirit::ostream_iterator It;

    karma::rule<It, Parameter()>   gen;
    karma::rule<It, std::string()> str;

    str = '"' << *('\\' << karma::char_('"') | karma::char_) << '"';
    gen = (karma::int_ | str | '{' << gen % ", " << '}');

    for (Parameter p : Parameters { 
            1, 
            "foo",
            Parameters { 1, "foo" },
            Parameters { 1, "escape: \"foo\"", Parameters { "2", "bar" } } 
       })
    {
        std::cout << karma::format(gen, p) << '\n';
    }
}

(Added a solution that simplifies the rules, and fixes the quoting but doesn't alter the attribute structure, for completeness)

Thank you, I wasn't trying to have it defined recursively, should have stated that clearly. Your solution is very good and solves it. I marked Mike_M's though since it pinpoints the problem exactly and doesn't introduce recursion. However I still do not understand why adding the quotation marks made the code not work.

boost::spirit::karma output of string in quotation marks - Stack Overf...

boost boost-spirit boost-variant boost-spirit-karma
Rectangle 27 0

The slash is just R's escape character. Used in this context it allows a quotation mark without closing the string. Although it appears in R console output, it doesn't appear when writing out to a file and it and the character you are escaping are counted as a single character:

x <- "ab\"c"
x
[1] "ab\"c"
writeLines(x)
ab"c
nchar(x)
[1] 4

json - R list toJSON without slash symbols - Stack Overflow

json r list
Rectangle 27 0

Always use mysql_real_escape_string when dealing with strings that might have quotation marks / slashes. If you don't, you'll get broken / malicious queries. The output of serialize() sometimes has quotation marks / slashes, so you should use it. There's no need to serialize the each item of the array beforehand though.

$details['name']  = $_POST['name'];
$details['email'] = $_POST['email'];
$details['phone'] = $_POST['phone'];

$serializedDetails = mysql_real_escape_string(serialize($details));

Just as an example: serializing "hello" will give you: s:5:"hello".

$data  = 's:5:"hello"';
$query = 'INSERT INTO tbl (data) VALUES ("' . $data . '")';

// leads to a syntax error from mysql
// (plus it's a huge security hole)
mysql_query($query);

php - Sanitizing when storing serialized array - Stack Overflow

php mysql serialization sanitization
Rectangle 27 0

The Jackson annotation @JsonValue tells Jackson that Jackson should not attempt to serialize the object itself, but rather call a method on the object which serializes the object to a JSON string. Note that Jackson will escape any quotation marks inside the String returned by the custom serialization, so you cannot return e.g. a full JSON object. For that you should use @JsonRawValue instead (see previous section).

The @JsonValue annotation is added to the method that Jackson is to call to serialize the object into a JSON string. Here is an example showing how to use the @JsonValue annotation:

public class PersonValue {

    public long   personId = 0;
    public String name = null;

    @JsonValue
    public String toJson(){
        return this.personId + "," + this.name;
    }

}

The output you would get from asking Jackson to serialize a PersonValue object is this:

"0,null"

So you can use @JsonValue and put your code either to ignore or not from some fields when you try to convert into JSON

@JsonValue
public String toJson(){
    //ignore fields or include them here
}

Spring Boot request body semi-required fields - Stack Overflow

spring spring-mvc spring-boot jackson
Rectangle 27 0

The description method of NSDictionary (which is used if you output a dictionary with NSLog, or print it in the debugger) encloses strings in quotation marks only if they contain special characters.

This output format is described in Old-Style ASCII Property Lists in the "Property List Programming Guide":

The quotation marks can be omitted if the string is composed strictly of alphanumeric characters and contains no white space (numbers are handled as strings in property lists). ...

Note that in general you cannot deduce the type from the NSLog() output. 123 can be a number or a string. But in this case, shape can only be a string.

Thanks a bunch!

objective c - Non-string key in NSDictionary object? - Stack Overflow

objective-c json nsstring nsdictionary
Rectangle 27 0

If you iterate your data types, you should iterate your rules.

#include <iostream>
#include <string>
#include <boost/variant.hpp>
#include <boost/spirit/include/karma.hpp>
namespace karma = boost::spirit::karma;

typedef boost::variant<int, std::string> Item;
typedef std::vector<Item> ParameterList;
typedef boost::variant<int, std::string, ParameterList> Parameter;

int main()
{
  using karma::int_;
  using boost::spirit::ascii::string;
  using karma::eol;
  using karma::lit;

  std::string generated;
  std::back_insert_iterator<std::string> sink(generated);

  karma::rule<std::back_insert_iterator<std::string>, Item()> itemRule =
      int_ | (lit('"') << string << lit('"'));

  karma::rule<std::back_insert_iterator<std::string>, ParameterList()>
    parameterListRule =  itemRule % lit(", ");

  karma::rule<std::back_insert_iterator<std::string>, Parameter()>
    parameterRule = (int_ | (lit('"') << string << lit('"')) | parameterListRule) << eol;

  karma::generate(sink, parameterRule, 1);
  karma::generate(sink, parameterRule, "foo");
  karma::generate(sink, parameterRule, Parameter(ParameterList {1, "foo"}));
  std::cout << generated;

  return 0;
}

This solves it exactly. Any explanation as to why line (1) worked and line (2) didn't?

Sorry no. From the composition itself one would expect it, but it seems karma has some problems forwarding the attributes here, although karma::lit does not expose any. But I'm no expert here, maybe @sehe knows more about this. But you learn to work around those quirks quickly ;-)

boost::spirit::karma output of string in quotation marks - Stack Overf...

boost boost-spirit boost-variant boost-spirit-karma
Rectangle 27 0

If you see the output in the console, which it's seems you are, those quotes are only to indicate it's a string.

console.log("You see!"); // "You see!"
alert("You see!"); // You see!

javascript - removing quotation marks from responsetext property - Sta...

javascript ajax json
Rectangle 27 0

Assuming either the key or value contains a quotation mark. The following will output the value after the ":". You can also use it in a loop to repeatedly extract the value field if you have multiple key-value pairs in the input string, provided that you keep a record of the position of last found instance.

#include <iostream>
using namespace std;

string extractInformation(size_t p, string key, const string& theEntireString)
{
  string s = "\"" + key +"\":\"";
  auto p1 = theEntireString.find(s);
  if (string::npos != p1)
    p1 += s.size();
  auto p2 = theEntireString.find_first_of('\"',p1);
  if (string::npos != p2)
    return theEntireString.substr(p1,p2-p1);
  return "";
}

int main() {
  string data = "\"key\":\"val\" \"key1\":\"val1\"";
  string res = extractInformation(0,"key",data);
  string res1 = extractInformation(0,"key1",data);
  cout << res << "," << res1 << endl;
}
val,val1

Please note that the backslash is only needed to escape the quote mark ". So what's "XXXXX\"key\":\"val\"XXXXX\"key1\":\"val1\"XXXXXXX" on disk will become string data = "XXXXX"key":"val"XXXXX"key1":"val1"XXXXXXX" in cxx code. If you modify the code to read a file or from stdin, you will see.

Equivalently, you can also use the c++11 raw string syntax, string data = R"(XXXXX"key":"val"XXXXX"key1":"val1"XXXXXXX)";, which does not require escaping special characters.

How to extract a substring from a string in C++? - Stack Overflow

c++ string
Rectangle 27 0

A string in javascript is enclosed in '' or in "", but the example you gave as neither. If you are sure that quotation marks will not be part of the output, enclose @Html.Raw(...) with quotation marks. eg. LoadXMLString('RfqXmlData', '@Html.Raw(...)');

If the string output of @Html.Raw(...) contains single quotes, this would break tho.. you might want to replace "'" with "\'" as well in that case.

I actually thought of that right after I posted the question. I tried it with @Html.Raw("'" + Model.RfqXmlData.. + "'"). Your way is better, though.

asp.net - Javascript unexpected token '<' when loading XML from model ...

javascript asp.net xml asp.net-mvc razor
Rectangle 27 0

By the looks of it, Write includes the quotation marks of the string file when writing to stream, so the output file starts with something like "GIF.... instead of just GIF.... When using BinaryWrite instead of Write it does seem to work. For example

file = ExportString[graphic, "GIF"];
stream = OpenWrite["streamoutput.gif", BinaryFormat -> True];
BinaryWrite[stream, file];
Close[stream];
Import["streamoutput.gif"]
ExportString

I confirmed that this solution works for EMF on Windows as well.

wolfram mathematica - Converting graphics with ExportString - Stack Ov...

wolfram-mathematica
Rectangle 27 0

Well there are no of ways of saving text from textfield within quotes into string.

//I already set text = hi in the UITextfield
    @IBOutlet weak var text: UITextField!
    override func viewDidLoad() {
    super.viewDidLoad()

    //1st way
    let s = "\""+text.text+"\""
    println(s)
    // Output:   


    //2nd way
    let t = "\"\(text.text)\""
    println(s)
    }

xcode - Swift UItextfield text with quotation marks from user to a str...

xcode osx swift double-quotes