Unable to convert from NavJsonValue to NavDate - microsoft-dynamics

After making a Get-Request to an Endpoint, I parse the returned Json String key by key, which works. The problem occurs when I try to convert the returned Date ('createdAt') to Date Type.
The error I receive
Die Konvertierung von Microsoft.Dynamics.Nav.Runtime.NavJsonValue in
Microsoft.Dynamics.Nav.Runtime.NavDate ist nicht möglich.
Which translates to something like:
Unable to convert from NavJsonValue to NavDate
The Json I parse
{
"entryNo": "2",
"title": "TEST",
"description": "Test Item",
"websiteUrl": "Test Url",
"createdAt": "14.01.2021"
}
Relevant code
_testEntry.CreatedAt := GetJsonToken(jsonObject, 'createdAt').AsValue().AsDate();
local procedure GetJsonToken(jsonObject: JsonObject; tokenKey: Text) jsonToken: JsonToken;
begin
if not jsonObject.Get(tokenKey, jsonToken) then
exit;
end;

The date format returned is not a valid JavaScript format, which is what AsDate() expects.
If you control the endpoint you should alter the date format to YYYY-MM-DD.
If you have no control over the endpoint then you need to parse the date value:
local procedure ParseDate(Token: JsonToken): Date
var
DateParts: List of [Text];
Year: Integer;
Month: Integer;
Day: Integer;
begin
// Error handling omitted from example
DateParts := Token.AsValue().AsText().Split('.');
Evaluate(Day, DateParts.Get(1));
Evaluate(Month, DateParts.Get(2));
Evaluate(Year, DateParts.Get(3));
exit(DMY2Date(Day, Month, Year));
end;

Related

AmazonCloudWatch PutMetricData request format parsing

How to parse PutMetricData Sample Request as show below.
I want to parse all the MetricData and stores the values in a struct in golang.
https://monitoring.&api-domain;/doc/2010-08-01/
?Action=PutMetricData
&Version=2010-08-01
&Namespace=TestNamespace
&MetricData.member.1.MetricName=buffers
&MetricData.member.1.Unit=Bytes
&MetricData.member.1.Value=231434333
&MetricData.member.1.Dimensions.member.1.Name=InstanceID
&MetricData.member.1.Dimensions.member.1.Value=i-aaba32d4
&MetricData.member.1.Dimensions.member.2.Name=InstanceType
&MetricData.member.1.Dimensions.member.2.Value=m1.small
&MetricData.member.2.MetricName=latency
&MetricData.member.2.Unit=Milliseconds
&MetricData.member.2.Value=23
&MetricData.member.2.Dimensions.member.1.Name=InstanceID
&MetricData.member.2.Dimensions.member.1.Value=i-aaba32d4
&MetricData.member.2.Dimensions.member.2.Name=InstanceType
&MetricData.member.2.Dimensions.member.2.Value=m1.small**
&AUTHPARAMS
Not able to understand this is in which format and how to parse it. Any library available to generate and parse this kind of formatted message?
If you remove the newlines that is a URL. Start with url.Parse, then use the Query() function to get access to the url parameters:
func main() {
var input = `https://monitoring.&api-domain;/doc/2010-08-01/
?Action=PutMetricData
&Version=2010-08-01
&Namespace=TestNamespace
&MetricData.member.1.MetricName=buffers
&MetricData.member.1.Unit=Bytes
&MetricData.member.1.Value=231434333
&MetricData.member.1.Dimensions.member.1.Name=InstanceID
&MetricData.member.1.Dimensions.member.1.Value=i-aaba32d4
&MetricData.member.1.Dimensions.member.2.Name=InstanceType
&MetricData.member.1.Dimensions.member.2.Value=m1.small
&MetricData.member.2.MetricName=latency
&MetricData.member.2.Unit=Milliseconds
&MetricData.member.2.Value=23
&MetricData.member.2.Dimensions.member.1.Name=InstanceID
&MetricData.member.2.Dimensions.member.1.Value=i-aaba32d4
&MetricData.member.2.Dimensions.member.2.Name=InstanceType
&MetricData.member.2.Dimensions.member.2.Value=m1.small**
&AUTHPARAMS`
// possibly also needs to replace \r
input = strings.ReplaceAll(input, "\n", "")
uri, err := url.Parse(input)
if err != nil {
log.Fatal(err)
}
for key, val := range uri.Query() {
fmt.Println(key, val)
}
}
Playground
From here on out it's up to you how you want the target struct to look like.

Parsing Json using arduino-mqtt lib

I am trying to use the arduino-mqtt lib.
I have this working sending the json string. The problem comes with trying to parse the string with ArduinioJson. It just returns no value.
I think it may have todo with the pointer reference in the mqttMessageRecived function ( String &payload).
Function called when there is an MQTT message:
void mqttMessageReceived(String &topic, String &payload){
//Example String for test
String json = "{"id" : "100" , "cmd" : "0xff"}";
jsonout(payload);
Serial.println("Sending Static String");
jsonout(json);
Function to parse json input:
void jsonout(String Json){
StaticJsonDocument<200> doc;
//Deserialize the JSON document
DeserializationError error = deserializeJson(doc, Json);
Serial.println("Got String: ");
Serial.println(Json);
// Test if parsing succeeds.
if (error) {
Serial.print(F("deserializeJson() failed: "));
Serial.println(error.c_str());
return;
}
const char* id = doc["id"];
const char* cmd = doc["cmd"];
// Print values.
Serial.println(id);
Serial.println(cmd);
}
Non parsed output:
Message from MQTT
Got String:
"{\"id\" : 4 , \"cmd\": \"0xee\"}"
Result = No output from json parse
Non parsed output:
Sending Static String
Got String:
{"id" : "100" , "cmd" : "0xff"}
Result = Output from json parse:
100
0xff
The problem is that - in the response from the server
"{\"id\" : 4 , \"cmd\": \"0xee\"}"
the id field is an integer - not a character array.
So you need to change
const char* id = doc["id"];
to
int id = doc["id"];
(and update your test string to use an int for the ID also).
The server returns a id member that's a Number "id":4, while you are generating a id that's a String "id":"200".
You need to adjust your code to either one. If it's a number (and it seems so), you need to send "id":200 and change your code to get a number:
unsigned id = (double)doc["id"];
// And to generate it:
String json = "{\"id\" : 100 , \"cmd\" : \"0xff\"}";
Also, with JSON, beware of hexadecimal encoding, has it's not converted to number (you have to do it yourself by receiving a const char* and calling sscanf or strtol or ...) and it's not convenient. It's better to use base-10 encoding instead:
String json = "{\"id\" : 100 , \"cmd\" : 255}";

Not able to get values from JSON in Casablanca, C++

I'm using Casablanca, cpprestsdk to consume REST APIs in C++, in Visual Studio 2015 Professional. I'm trying to develop a simple example here hitting an API and parsing the response as JSON. The URL I'm using, actually returns all the parameters sent to the API.
I've hit the API and got response as well, extracted json from the response successfully. But when i try to read a value at any key from json, it crashes. Hence i put a check whether that key is available or not, and it always says json does not have the field. As an example i printed the data i.e. json. It has the key/field "name" but when i check it via has_field, it returns false.
Please help.
Complete code is below :
json::value postData;
postData[L"name"] = json::value::string(L"Joe Smith");
postData[L"sport"] = json::value::string(L"Baseball");
http_client client(L"https://httpbin.org/post);
http_request request(methods::POST);
request.set_body(postData);
client.request(request).then([](web::http::http_response response) {
json::value j = response.extract_json().get();
json::value data = j.at(U("data"));
std::wcout << "Json : " << data;
// Prints "{\"name\":\"Joe Smith\",\"sport\":\"Baseball\"}"
if (data.has_field(U("name"))) {
std::cout << "Name Found";
}
else {
std::cout << "Name key not Found";
}
});
It seems that your response looks like this:
{ "data": "{\"name\":\"Joe Smith\",\"sport\":\"Baseball\"}" }`
i.e. the actual data is not a JSon object but escaped JSon passed as string. I guess you need to return a payload that looks like this to do what you want to do the way you are doing it:
{
"data": {
"name": "John Smith",
"sport": "Baseball"
}
}

ORA-00904: "E_MAIL": invalid identifier

I am using MVC architecture.I am trying to update a record in a table taking customer id as input.
all the data is taken as input in my viewcustomer.cpp class whose method is returning an object of type customer which is passed to a function in modelcustomer.pc via controlcustomer.cpp(controller)
Following is a function of my modelcustomer.pc
void modelcustomer::dbUpdateCustomerDetail(customer &c)
{
id=c.getId();
ph=c.getId();
string memberFName=c.getFname();
string memberLName=c.getLname();
string memberStreet=c.getStreet();
string memberCity=c.getCity();
string memberState=c.getState();
string memberEmail=c.getEmail();
fn=new char[memberFName.length()+1];
ln=new char[memberLName.length()+1];
street=new char[memberStreet.length()+1];
city=new char[memberCity.length()+1];
state=new char[memberState.length()+1];
e_mail=new char[memberEmail.length()+1];
strcpy(fn,memberFName.c_str());
strcpy(ln,memberLName.c_str());
strcpy(street,memberStreet.c_str());
strcpy(city,memberCity.c_str());
strcpy(state,memberState.c_str());
strcpy(e_mail,memberEmail.c_str());
if(dbConnect())
{
EXEC SQL UPDATE CUSTOMER_1030082 SET CID=:id,FNAME=:fn,LNAME=:ln,PHONE=:ph,STREET=:street,STATE=:state,CITY=:city,EMAIL=e_mail;
if(sqlca.sqlcode<0)
{
cout<<"error in execution"<<sqlca.sqlcode<<sqlca.sqlerrm.sqlerrmc;
}
EXEC SQL COMMIT WORK RELEASE;
}
}
when i'm running it a menu is displayed with some options ,i select the update option then it asks me for new details and after that i'm getting following output:
connected to Oracle!
error in execution-904ORA-00904: "E_MAIL": invalid identifier
e_mail is not a parameter, you forgot ::
EXEC SQL … EMAIL=:e_mail;
↑

How can I query remembered UNC connections similar to "net use"?

I understand how to retrieve the UNC path for a mapped drive from the registry (HKEY_CURRENT_USER\Network), but I also have a need to retrieve remote connections to network resources that were not mapped.
For example, opening the 'Run' dialog and typing <\server0123\share$>. If I type "net use", I would see this mapping, but I have been unable to determine where on the file system or registry this information is stored.
alt text http://www.freeimagehosting.net/uploads/5bf1a0e3c5.jpg
Does anyone know have a location I can query this from, or an API I can call to obtain this? Suggestions involving vbscript, C, and Delphi are more than welcome!
Mick, try using the Win32_NetworkConnection WMI Class
check this sample
program GetWMI_Win32_NetworkConnection;
{$APPTYPE CONSOLE}
uses
SysUtils
,ActiveX
,ComObj
,Variants;
Procedure GetWin32_NetworkConnection;
var
objWMIService : OLEVariant;
colItems : OLEVariant;
colItem : OLEVariant;
oEnum : IEnumvariant;
iValue : LongWord;
function GetWMIObject(const objectName: String): IDispatch;
var
chEaten: Integer;
BindCtx: IBindCtx;
Moniker: IMoniker;
begin
OleCheck(CreateBindCtx(0, bindCtx));
OleCheck(MkParseDisplayName(BindCtx, StringToOleStr(objectName), chEaten, Moniker));
OleCheck(Moniker.BindToObject(BindCtx, nil, IDispatch, Result));
end;
begin
objWMIService := GetWMIObject('winmgmts:\\localhost\root\cimv2');
colItems := objWMIService.ExecQuery('SELECT * FROM Win32_NetworkConnection','WQL',0);
oEnum := IUnknown(colItems._NewEnum) as IEnumVariant;
while oEnum.Next(1, colItem, iValue) = 0 do
begin
Writeln('Caption '+colItem.Caption);
Writeln('Name '+colItem.Name);
Writeln('ConnectionState'+colItem.ConnectionState);
Writeln('ConnectionType '+colItem.ConnectionType);
Writeln('Description '+colItem.Description);
Writeln('DisplayType '+colItem.DisplayType);
Writeln('LocalName '+colItem.LocalName);
Writeln('ProviderName '+colItem.ProviderName);
Writeln('RemoteName '+colItem.RemoteName);
Writeln('RemotePath '+colItem.RemotePath);
Writeln('ResourceType '+colItem.ResourceType);
Writeln('Status '+colItem.Status);
Writeln('UserName '+colItem.UserName);
Writeln;
end;
end;
begin
try
CoInitialize(nil);
try
GetWin32_NetworkConnection;
Readln;
finally
CoUninitialize;
end;
except
on E:Exception do
Begin
Writeln(E.Classname, ': ', E.Message);
Readln;
End;
end;
end.
WNetOpenEnum(RESOURCE_REMEMBERED,...)
(If you need to support Win9x, you probably have to fall back to NetUseEnum)