I started testing OrientDB. I get the following JSON Response from the Demo Database:
{
"schema":{
"name":"OUser",
"properties":{
"roles":{
"name":"roles",
"linkedClass":"ORole",
"type":"LINKSET",
"mandatory":false,
"notNull":true,
"min":null,
"max":null
},
"name":{
"name":"name",
"type":"STRING",
"mandatory":true,
"notNull":false,
"min":null,
"max":null
},
"password":{
"name":"password",
"type":"STRING",
"mandatory":true,
"notNull":false,
"min":null,
"max":null
}
}
},
"result":[
{
"#type":"d",
"#rid":"#4:0",
"#version":0,
"#class":"OUser",
"name":"admin",
"password":"{SHA-256}8C6976E5B5410415BDE908BD4DEE15DFB167A9C873FC4BB8A81F6F2AB448A918",
"status":"ACTIVE",
"roles":[
"#3:0"
]
},
{
"#type":"d",
"#rid":"#4:1",
"#version":0,
"#class":"OUser",
"name":"reader",
"password":"{SHA-256}3D0941964AA3EBDCB00CCEF58B1BB399F9F898465E9886D5AEC7F31090A0FB30",
"status":"ACTIVE",
"roles":[
"#3:1"
]
},
{
"#type":"d",
"#rid":"#4:2",
"#version":0,
"#class":"OUser",
"name":"writer",
"password":"{SHA-256}B93006774CBDD4B299389A03AC3D88C3A76B460D538795BC12718011A909FBA5",
"status":"ACTIVE",
"roles":[
"#3:2"
]
}
]
}
How can you get a List of OUser Objects out of that? Using JSON.Net, JavaScriptSerializer or whatever?
There are a number of json parsers for c# at:
http://www.json.org/. It seems like fastJSON should be pretty quick.
Once logged in execute a query against OUser class:
select from ouser
Via HTTP protocol would be a GET request against this address:
http://localhost:2480/query/demo/sql/select%20from%20ouser
{
"result": [{
"#type": "d", "#rid": "#4:0", "#version": 0, "#class": "OUser",
"name": "admin",
"password": "{SHA-256}8C6976E5B5410415BDE908BD4DEE15DFB167A9C873FC4BB8A81F6F2AB448A918",
"status": "ACTIVE",
"roles": ["#3:0"]
}, {
"#type": "d", "#rid": "#4:1", "#version": 2, "#class": "OUser",
"name": "reader",
"password": "{SHA-256}3D0941964AA3EBDCB00CCEF58B1BB399F9F898465E9886D5AEC7F31090A0FB30",
"status": "ACTIVE",
"roles": ["#3:1"]
}, {
"#type": "d", "#rid": "#4:2", "#version": 0, "#class": "OUser",
"name": "writer",
"password": "{SHA-256}B93006774CBDD4B299389A03AC3D88C3A76B460D538795BC12718011A909FBA5",
"status": "ACTIVE",
"roles": ["#3:2"]
}
]
}
this looks like an easy structure to deserialise using json.NET
Related
I have created account with Postmen site at: https://secure.postmen.com/login
I got API Key.
I am referring to documentation at: https://docs.postmen.com/fedex.html#rates-calculate-rates/
Below is the JSON I am submitting and I am getting "Operation Forbidden" Error.
What am i missing? Do i need to pass any other params? Appreciate your responses.
In the Postman Header, I am specifying content-type as application/json and passing postmen-api-key as well.
Since I already created account, I got Shipper Account ID.
This is the Rates URL: https://secure.postmen.com/explorer/sandbox/v3/rates
I am testing everything in POSTMAN.
JSON:
{
"async": false,
"shipper_accounts": [
{
"id": "My Account ID XXXX"
}
],
"is_document": false,
"shipment": {
"ship_from": {
"contact_name": "Elmira Zulauf",
"company_name": "Kemmer-Gerhold",
"street1": "5800 Windward Pkwy",
"city": "Alpharetta",
"state": "GA",
"postal_code": "30005",
"country": "USA",
"type": "business"
},
"ship_to": {
"contact_name": "Dr. Moises Corwin",
"phone": "1-140-225-6410",
"email": "Giovanna42#yahoo.com",
"street1": "1800 W Hillcrest Dr",
"city": "Newbury Park",
"postal_code": "91320",
"state": "CA",
"country": "USA",
"type": "residential"
},
"parcels": [
{
"description": "Food XS",
"box_type": "custom",
"weight": {
"value": 2,
"unit": "kg"
},
"dimension": {
"width": 20,
"height": 40,
"depth": 40,
"unit": "cm"
},
"items": [
{
"description": "Food Bar",
"origin_country": "USA",
"quantity": 2,
"price": {
"amount": 3,
"currency": "USD"
},
"weight": {
"value": 0.6,
"unit": "kg"
},
"sku": "imac2014"
}
]
}
]
}
}
Appreciate your responses.
Thanks
Rita
If you are testing via POSTMAN, according to https://docs.postmen.com/, full url for calculate rates should be like below,
Sandbox: https://sandbox-api.postmen.com/v3/rates
Production: https://production-api.postmen.com/v3/rates
sandbox can be used for testing
I'm trying to create an Azure container instance and mounting a File Storage volume via REST API, but I'm getting 400 response.
I'm able to create the container and keep it running but when I add the volume part it returns a 400 response (Bad request) without further explanation
Here is the JSON payload I'm sending to the REST endpoint:
{
"id": "/subscriptions/111111111/resourceGroups/OraResourceGroup/providers/Microsoft.ContainerInstance/containerGroups/solver",
"location": "West Europe",
"name": "solver",
"properties": {
"volumes": [
{
"azureFile": {
"shareName": "orafileshare",
"storageAccountKey": "somekey",
"storageAccountName": "myaccountname"
},
"name": "Volume1"
}
],
"containers": [
{
"name": "solver",
"properties": {
"command": [],
"environmentVariables": [],
"image": "acraccount/solver:v1",
"ports": [
{
"port": 12345
}
],
"resources": {
"requests": {
"cpu": 1.0,
"memoryInGB": 1.5
}
},
"volumeMounts": [
{
"name": "Volume1",
"mountPath": "/mountFolder"
}
]
}
}
],
"imageRegistryCredentials": [
{
"password": "123123123213123",
"server": "acr.server.io",
"username": "acrOra"
}
],
"ipAddress": {
"ports": [
{
"protocol": "TCP",
"port": 12345
}
],
"type": "Public"
},
"osType": "Linux",
"restartPolicy": "Always"
},
"type": "Microsoft.ContainerInstance/containerGroups"
}
The expected results is a 200 or 201 response and the container should appear on my Azure portal dashboard but the actual response is 400.
There are 2 issues with this correction. I also received 400 bad request but later corrected it and I was able to run it successfully.
Name of volume, capital letter is not allowed.
Change "Volume1" to "volume1"
Reference Error :
{"error":{"code":"InvalidVolumeName","message":"The volume name 'Volume1' is invalid. The volume name must match the regex '[a-z0-9]([-a-z0-9]*[a-z0-9])?' (e.g. 'my-name')."}}
Sku is not a valid property, Remove it
{"error":{"code":"InvalidRequestContent","message":"The request
content was invalid and could not be deserialized: 'Could not find
member 'sku' on object of type 'ComputeResources'. Path
'properties.containers[0].properties.resources.requests.sku', line 32,
position 22.'."}}
Reference https://learn.microsoft.com/en-us/rest/api/container-instances/containergroups/createorupdate#resourcerequests
Sample configuration
{
"id": "/subscriptions/xxxx/resourceGroups/teststoragerest/providers/Microsoft.ContainerInstance/containerGroups/solver",
"location": "West Europe",
"name": "demo1forrahul",
"properties": {
"volumes": [
{
"azureFile": {
"shareName": "testfilestorage",
"storageAccountKey": "xxxx",
"storageAccountName": "xxxxxx"
},
"name": "volume1"
}
],
"containers": [
{
"name": "demo1forrahul",
"properties": {
"command": [],
"environmentVariables": [],
"image": "nginx",
"ports": [
{
"port": 80
}
],
"resources": {
"requests": {
"cpu": 1.0,
"memoryInGB": 1.5
}
},
"volumeMounts": [
{
"name": "volume1",
"mountPath": "/testfolder"
}
]
}
}
],
"imageRegistryCredentials": [],
"ipAddress": {
"ports": [
{
"protocol": "TCP",
"port": 80
}
],
"type": "Public"
},
"osType": "Linux",
"restartPolicy": "Always"
},
"type": "Microsoft.ContainerInstance/containerGroups"
}
Below is the JSON when I call my LUIS api endpoint.
{
"query": "How do I install citrix?",
"topScoringIntent": {
"intent": "Setup Instructions",
"score": 0.9999997
},
"intents": [
{
"intent": "Setup Instructions",
"score": 0.9999997
},
{
"intent": "OS Availability",
"score": 0.0000021111066
},
{
"intent": "Service Guide",
"score": 8.18181149e-7
},
{
"intent": "Service Description",
"score": 5.55555232e-7
},
{
"intent": "None",
"score": 9e-9
},
{
"intent": "Greeting",
"score": 1.41666667e-9
},
{
"intent": "Compassion",
"score": 8.1e-10
},
{
"intent": "Images",
"score": 8.1e-10
}
],
"entities": [
{
"entity": "citrix",
"type": "Service",
"startIndex": 17,
"endIndex": 22,
"resolution": {
"values": [
"Citrix Receiver"
]
},
"role": ""
}
],
"sentimentAnalysis": {
"label": "positive",
"score": 0.7695234
}
}
I am trying to get the string "Citrix Receiver" from below.
Below is my code
LuisResult result
var strEntity = result.Entities[0].Resolution.Values[0]
but I cannot apply indexing to an expression of type ICollection<object>. It looks as though resolution is defined as a dictionary and upon researching, I have seen other JSON bodies with the resolution having multiple key value pairs. Is it possible the body has changed but the Luis extension in the MS Bot Builder Framework has not?
Thanks.
I had the same problem previously to get a list of resolved entities, I resolved it using the following code:
result.Entities.First().Resolution.Values.Select(s => JArray.Parse(s.ToString()).Distinct().ToList();
So for you it may be a bit shorter like:
result.Entities.First().Resolution.Values.First(s => JArray.Parse(s.ToString());
Example:
"database": {
"UUIDTOKEN": {
"name": "test",
"yearsold": "20",
"userid": "100",
"uuid": "a2b45475-aebe-4103-9c01-43ea8754dfc0",
"email": "email#gmail.com"
}
},
How to add new value ? so, database = main json text. How to add uuid {
name,yearsold,userid,uuid,email
}
"database": {
"UUIDTOKEN": {
"name": "test",
"yearsold": "20",
"userid": "100",
"uuid": "a2b45475-aebe-4103-9c01-43ea8754dfc0",
"email": "email#gmail.com"
},
"UUIDTOKEN": {
"name": "stackoverflow",
"yearsold": "24",
"userid": "110",
"uuid": "uuid-aebe-4103-9c01-43ea8754dfc0",
"email": "stackoverflow#gmail.com"
},
},
Thanks for help.
An object (the "database" in your case) can't have two fields with the same name ("UUIDTOKEN"). If you need your "database" to contain a list of "UUIDTOKEN" objects, consider changing it to an array:
{
"database": [{
"name": "test",
"yearsold": "20",
"userid": "100",
"uuid": "a2b45475-aebe-4103-9c01-43ea8754dfc0",
"email": "email#gmail.com"
}, {
"name": "stackoverflow",
"yearsold": "24",
"userid": "110",
"uuid": "uuid-aebe-4103-9c01-43ea8754dfc0",
"email": "stackoverflow#gmail.com"
}]
}
Please note, the "UUIDTOKEN" name was eliminated in this sample, but if you need it for some reason, add another object layer:
{
"database": [{
"UUIDTOKEN": {
"name": "test"
//...
}
}, {
"UUIDTOKEN": {
"name": "stackoverflow"
//...
}
}]
}
I'm not exactly sure what you are asking? Do you want to know how to add another value to a json object in c#, or do you want to know why what you've written won't work?
If it's the latter, you can't have a json object with 2 keys the same, you will need to change UUIDTOKEN to a unique key. Otherwise you could use an array.
I've successfully created code that serializes a complex javascript object and posts it to an ASP.NET page. I can get the JSON string using Request.Form and the result looks like this (I've added indentation for readability):
{
"gasterPerStolPerVecka": {
"name": "gasterPerStolPerVecka",
"keyValue_id": "2",
"set_id": "1",
"containerElement": "#gasterPerStolPerVecka",
"keyValueComponents": [
{
"name": "gasterPerStolPerVecka_guestsPerWeek",
"value": "200"
},
{
"name": "gasterPerStolPerVecka_numberOfChairs",
"value": "100"
}
],
"keyValueUnitText": "gäster/stol per vecka",
"keyValueCalculationMethod": "divide",
"isValid": true,
"result": 2
},
"tillgangligaStolstimmarPerVecka": {
"name": "tillgangligaStolstimmarPerVecka",
"keyValue_id": "1",
"set_id": "1",
"containerElement": "#tillgangligaStolstimmarPerVecka",
"keyValueComponents": [
{
"name": "tillgangligaStolstimmarPerVecka_openHoursPerWeek",
"value": "35"
},
{
"name": "tillgangligaStolstimmarPerVecka_numberOfChairs",
"value": "100"
}
],
"keyValueUnitText": "stolstimmar/vecka",
"keyValueCalculationMethod": "multiply",
"isValid": true,
"result": 3500
},
"planeradIntaktPerTillgangligStolOchVecka": {
"name": "planeradIntaktPerTillgangligStolOchVecka",
"keyValue_id": "",
"set_id": "",
"containerElement": "#planeradIntaktPerTillgangligStolOchVecka",
"keyValueComponents": [
{
"name": "planeradIntaktPerTillgangligStolOchVecka_weeklyRevenue",
"value": ""
},
{
"name": "planeradIntaktPerTillgangligStolOchVecka_numberOfChairs",
"value": "100"
}
],
"keyValueUnitText": "kr",
"keyValueCalculationMethod": "divide",
"isValid": false,
"result": null,
"errorText": "Ofullständigt underlag för beräkning."
},
"planeradIntaktPerTillgangligaStolstimmar": {
"name": "planeradIntaktPerTillgangligaStolstimmar",
"keyValue_id": "",
"set_id": "",
"containerElement": "#planeradIntaktPerTillgangligaStolstimmar",
"keyValueComponents": [
{
"name": "planeradIntaktPerTillgangligaStolstimmar_weeklyRevenue",
"value": ""
},
{
"name": "planeradIntaktPerTillgangligaStolstimmar_openHoursPerWeek",
"value": "35"
},
{
"name": "planeradIntaktPerTillgangligaStolstimmar_numberOfChairs",
"value": "100"
}
],
"keyValueUnitText": "kr",
"keyValueCalculationMethod": "divide_divide",
"isValid": false,
"result": null,
"errorText": "Ofullständigt underlag för beräkning."
}
}
Now I try to deserialize this on the server side, but it's difficult. I keep getting the error:
[NullReferenceException: Object reference not set to an instance of an object.]
I don't know where to start looking for errors?
Thanks in advance!
/Thomas Kahn
use stringify instead serialization
You need to use a deserialization library for ASP.NET. See http://json.org/ for libraries that are available or maybe there is one built into ASP.NET. Either way, the code will look like:
String s = getAppropriateFormField();
Object o = JSONLibraryPackage.parse(s);
where obviously you'll have to fill in the blanks for how you get the form field and then what package and method does the parsing.