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.
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 having trouble to properly iterate with the json response i got. There's no specific id/key to loop them.
First here is my sample json object.
The key's of json is id and is dynamic.
Sample JSON
{
"1": {
"docid": "26",
"title": "QT1030-3 Product Development Plan Template",
"category": "Template/Form",
"children": {}
},
"2": {
"docid": "27",
"title": "QT1030-2 Product Requirements Template",
"category": "Template/Form",
"children": {}
},
"3": {
"docid": "28",
"title": "QT1030-1 Product Specifications Template",
"category": "Template/Form",
"children": {}
},
"60": {
"docid": "22",
"title": "QT1030-7 Design & Development Review Template",
"category": "Template/Form",
"children": {}
},
"61": {
"docid": "23",
"title": "QT1030-6 Design Inputs Outputs Matrix",
"category": "Template/Form",
"children": {}
},
"63": {
"docid": "24",
"title": "QT1030-5 DHF Index Template",
"category": "Template/Form",
"children": {}
},
"82": {
"docid": "25",
"title": "QT1030-4 Material Specifications",
"category": "Template/Form",
"children": {}
}
Here i tried to loop dynamic but not sure how to iterate properly.
I tried something like item.docid but no success.
C# code
C# Code
if (response.IsSuccessStatusCode)
{
var documents = await response.Content.ReadAsStringAsync();
dynamic nodelist = JsonConvert.DeserializeObject(documents);
foreach (var item in nodelist)
{
int i = 0;
}
}
You are almost there, you can iterate it and get value of docid as follow:
dynamic nodeList= JsonConvert.DeserializeObject(documents);
foreach (JProperty node in nodeList)
{
Console.WriteLine(node.Value["docid"]);
}
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());
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
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.