In Node.js 6.10, an API call returns JSON string:
in C# code is return "{\"response\" : \" " + responseMsg + " \" , \"isNewActiveDirectoryUser\" : \" " + isNewActiveDUser + " \"}";
this returns
"\"{\\\"response\\\" : \\\" Not latest version of file, update not performed \\\" , \\\"isNewActiveDirectoryUser\\\" : \\\" False \\\"}\""
I want to extract response & isNewActiveDirectoryUser and place the result in variables.
I have tried
context.done(null, body);
var jsonBody = JSON.parse(body);
let valueReturned1 = jsonBody.response; //have tried this
let valueReturned2 =jsonBody["response"]; //and this
both display undefined.
What am I doing wrong?
I can console.log the body and it is populated
Your json is double stringified.
JSON.parse(JSON.parse("\"{\\\"response\\\" : \\\" Not latest version of file, update not performed \\\" , \\\"isNewActiveDirectoryUser\\\" : \\\" False \\\"}\"")).response === " Not latest version of file, update not performed "
Sounds like you need to fix it on the C# side
Related
I have expression of
Validator.Format=^(csv|excel|Csv|Escel|CSV|EXCEL)$
Getting error
org.owasp.esapi.errors.ValidatornException: Invalid input. Please conform to regex
^(csv|excel|Csv|Escel|CSV|EXCEL)$ with maximum length of 5
Can you please suggest
There is not enough information to go on here. You at least need to say what version of ESAPI you are using and show me the full exception message. In the latest version of ESAPI at least, this exception only shows up here, in StringValidationRules.java as:
throw new ValidationException( context + ": Invalid input. Please conform to regex " + p.pattern() + ( maxLength == Integer.MAX_VALUE ? "" : " with a maximum length of " + maxLength ), "Invalid input: context=" + context + ", type(" + getTypeName() + ")=" + p.pattern() + ", input=" + input + (NullSafe.equals(orig,input) ? "" : ", orig=" + orig), context );
So display the rest of that exception message for starters.
Below is my code for inserting data in MYSQL in ExpressJS.
router.post('/user', function (req, res) {
let sql = "INSERT INTO Member (id, Memb_ID, First_Name, Middle_Name, Last_Name, Address, url) VALUES (null, '" + req.body.Memb_ID + "', '" + req.body.First_Name + "', '" + req.body.Middle_Name + "', '" + req.body.Last_Name + "', '" + req.body.Address + "', '" + req.body.url + "')";
myDB.query(sql, function (err, results) {
if (err) throw err;
res.send({
Success: "Data inserted."
})
});
});
It inserts data in my database but my database looks like this
I don't know why it outputs like that. Here's my JSON
EDIT :
Here is my MYSQL Table
Can you make sure that the following is done?
The content-type header in the request has to be application/json
Use body-parser (or similar libraries) to parse JSON payloads -> You can print the req.body to validate this.
If you can confirm that the values are accessible, I would suggest escaping query values as mentioned in https://github.com/mysqljs/mysql#escaping-query-values (or in any mysql library that you use) - especially since it is a DML query.
(Also I assume that the fieldnames used in the query match with the ones in the database and are of the right datatype.)
In your image of postman call, it's clearly showing your content type is text.
Change Content-type to application/json in your postman call headers
Or you can select from body tab
As your body content was text as shown in your image, it was sending a plain text that leading to undefined in DB. But the server was expecting json.
Hope that helps.
See wether you have added #RequestBody annotation in your respective method signature in Controller...
check this 1's bcz i had same issue i resolved after adding this..
it may help you and others... also...
i have this code here:
var sql = "select shr_id, shc_id " +
"from tbox_operational.shipment_ref " +
"inner join tbox_operational.shipment_collo_ref using (shr_id) " +
"where shr_insdtm between ?dateTimeFrom";
var parameters = new List<MySqlParameter> {
new MySqlParameter("?dateTimeFrom", dateTimeFrom.ToString("yyyy/MM/dd HH:mm:ss"))
};
var query = (from db in context.Database.SqlQuery<ShridsModel>(sql, parameters)
select db).ToList();
return query;
But it keeps me getting this error:
{"Parameter '?dateTimeFrom' must be defined."}
i have also in my connection string:
server=xxx;user id=runtime;password=xxxx;AllowUserVariables=True;
What am i doing wrong here?
I have solved...
Instead of passing a list of the parameters, i pass each one individual and he recognizes it all
I'm trying to do a search but did not get any result. This is wrong:
def BuscarRoles(usuario)
#sql="SELECT * FROM rols WHERE id_rol IN (SELECT id_rol FROM rol_usuarios WHERE id_usuario = "+usuario.to_s+")"
#roles = ActiveRecord::Base.connection.execute(#sql)
#tira='['
if #roles.count>0
#aroles.each do |rol|
#tira = #tira+" { id_rol: '" + rol.id_rol.to_s + "', descripcion: '" + rol.descripcion.to_s
j=j+1
if j<#roles.count
#tira = #tira+ " }, "
else
#tira = #tira+" } ] "
end
end
else
#tira= #tira+"{ { text: 'No hay datos', id: '0', href: '', leaf: true } } ]"
end
return #tira
end
By just looking at the code, with no trace given, I can only see one thing that might cause the error.
ActiveRecord::Base.connection.execute
#the result of the above code is Mysql2::Result of course depending on what database you're using.
Hence you can't use .(dot) operator on the result as you would do on a model object.
So you could make the following changes in the code
#aroles.each do |rol|
#puts rol.id_role => this will throw error
puts rol[0] # this should work assuming id_role is the first column
end
That should help. As you mentioned in the comment that your getting error in #aroles.each do |rol| then you must check if the sql statement is returning you any results at all ?
BTW, even if the query doesn't return any results, it would simply return an empty array and iterating an empty array would simple give nothing but not throw any error.
So to conclude
Check if any records are returned at all
Use index instead of the column name as they are active_record objects
Hope that helps.
I have couple of CSv input files with different filenames along with difeerent date formats. i need to select the input file dynamically based on a condition .
For example
i have files file120120909.csv, scalefile09102012.csv
i need to retrive the input file based on condition. So i have taken an user variable and return expression in this way
(#[User::Type] =="File" ? "file" : (#[User::type] =="scale" ? "scale_" :"NA")) + (DT_STR,4,1252)DATEPART("yyyy", #[System::StartTime] ) + RIGHT("0" + (DT_STR,2,1252) DATEPART("mm", #[System::StartTime]),2) + RIGHT("0" + (DT_STR,2,1252)DATEPART("dd", #[System::StartTime]),2)
when i evaluate the expression i got the following result
file120120912
now when i assign value for user variable #[User::Type] =="scale" then the expression result has to be scalefile09102012.
So based on condition how can i append the date for the file
You can write the VB.NET code into the script task to solve your issue:
Dim type As String = Dts.Variables("Type").Value.ToString()
Dim startDate As DateTime = DateTime.Parse(Dts.Variables("StartTime").Value.ToString())
Dim result As String = ""
If type.ToLower() = "file" Then
result = type.ToLower() + startDate.ToString("yyyyMMdd")
ElseIf type.ToLower() = "scale" Then
result = type.ToLower() + "file" + startDate.ToString("MMddyyyy")
Else
result = "incorrect type"
End If
MsgBox(result)