Could someone give me a hint as to the class structure to use to deserialise this Json response from the Wikipedia opensearch api:
[
"test",
[
"Test",
"Testosterone",
"Test (assessment)",
"Testicle",
"Test-driven development",
"Testosterone (medication)",
"Testicular cancer",
"Test cricket",
"Tests of general relativity",
"Test (wrestler)"
],
[
"",
"",
"",
"",
"",
"",
"",
"",
"",
""
],
[
"https://en.wikipedia.org/wiki/Test",
"https://en.wikipedia.org/wiki/Testosterone",
"https://en.wikipedia.org/wiki/Test_(assessment)",
"https://en.wikipedia.org/wiki/Testicle",
"https://en.wikipedia.org/wiki/Test-driven_development",
"https://en.wikipedia.org/wiki/Testosterone_(medication)",
"https://en.wikipedia.org/wiki/Testicular_cancer",
"https://en.wikipedia.org/wiki/Test_cricket",
"https://en.wikipedia.org/wiki/Tests_of_general_relativity",
"https://en.wikipedia.org/wiki/Test_(wrestler)"
]
]
Just using the core .Net libraries i.e. no NewtsonSoft libraries etc.
Related
when i am trying to configure tab in teams channel,i followed the steps from article https://learn.microsoft.com/en-in/microsoftteams/platform/tutorials/get-started-dotnet-app-studio i could not find selection of tab and save button enabled , why this happned? how to solve it?, I am using echo bot template which is running on bot emulator properly.
Following is the json
{
"$schema": "https://developer.microsoft.com/en-us/json-schemas/teams/v1.5/MicrosoftTeams.schema.json",
"manifestVersion": "1.5",
"version": "1.0.0",
"id": "2fac8fdd-7fa3-451f-8562-adba3ab84c8d",
"packageName": "com.contoso.helloworld",
"developer": {
"name": "Hello World App ",
"websiteUrl": "https://www.microsoft.com",
"privacyUrl": "https://www.microsoft.com/privacy",
"termsOfUseUrl": "https://www.microsoft.com/termsofuse"
},
"icons": {
"color": "color.png",
"outline": "outline.png"
},
"name": {
"short": "janApp",
"full": "janApp"
},
"description": {
"short": "SWAN Bot App for Microsoft Teams",
"full": "This sample app provides a very simple app for Microsoft Teams. You can extend this to add more content and capabilities."
},
"accentColor": "#A4D344",
"configurableTabs": [
{
"configurationUrl": "https://echobot57.azurewebsites.net/configure",
"canUpdateConfiguration": true,
"scopes": [
"team",
"groupchat"
]
}
],
"staticTabs": [
{
"entityId": "com.contoso.helloworld.hellotab",
"name": "Botdemo",
"contentUrl": "https://echobot57.azurewebsites.net/hello",
"websiteUrl": "https://echobot57.azurewebsites.net/hello",
"scopes": [
"personal"
]
}
],
"bots": [
{
"botId": "330b4c4d-5f92-4053-a38f-7d4593cfd18a",
"scopes": [
"personal",
"team",
"groupchat"
],
"supportsFiles": true,
"isNotificationOnly": true
}
],
"composeExtensions": [
{
"botId": "330b4c4d-5f92-4053-a38f-7d4593cfd18a",
"canUpdateConfiguration": true,
"commands": [
{
"id": "getRandomText",
"type": "query",
"title": "Get some random text for fun",
"description": "Gets some random text and images",
"initialRun": true,
"fetchTask": false,
"context": [
"commandBox",
"compose",
"message"
],
"parameters": [
{
"name": "cardTitle",
"title": "Card title",
"description": "Card title to use",
"inputType": "text"
}
]
}
]
}
],
"permissions": [
"identity",
"messageTeamMembers"
],
"validDomains": [
"echobot57.azurewebsites.net"
]
}
Please make sure the tab configuration url is correct.
If it is correct, you should be able to access it.
https://microsoftteamssampleshelloworldweb20200107021253.azurewebsites.net/configure
This question already has answers here:
Serialize and Deserialize Json and Json Array in Unity
(9 answers)
Closed 5 years ago.
I am new in unity and I need to download data from JSON. I successfully download JSON data but I am not able to parse the JSON. I have use Boomlagoon Asset to serialize my JSON. Here is my code.
void Start() {
string url = "http://www.windmillinfotech.com/carlife/carlife_api/get_workshop";
WWWForm form = new WWWForm();
form.AddField("district", "Dhaka");
form.AddField("thana", "Mirpur");
form.AddField("service_type", "car");
WWW www = new WWW( url, form );
StartCoroutine (request(www));
}
IEnumerator request (WWW www) {
yield return www;
if(!string.IsNullOrEmpty(www.error)) {
print( "Error : " + www.error );
} else {
string serviceData = www.text;
JSONObject json = JSONObject.Parse(serviceData);
print ("\n\n\n\n"+json["workshop_dtls_result"]);
}
}
and my JSON result is like follows,
{
"success": true,
"workshop_dtls_result": [
{
"id": "141",
"user_id": "",
"store_id": null,
"updated_by": null,
"workshop_name": "Okay Auto Engineering",
"workshop_email": "",
"workshop_address": "Section -10, Block - A, Plot - 9, Main Road, Mirpur, Dhaka-1216. Behind the graveyard, 01712978222",
"district": "Dhaka",
"thana": "Mirpur",
"post_code": "",
"contact_person": "Sabir Hossain",
"contact_number": "01712978222",
"alternative_number": "",
"service_type_car": "Car",
"service_type_bus": "",
"service_type_bike": "",
"workshop_photo_1": "",
"workshop_photo_2": "",
"workshop_photo_3": "",
"latitude": "",
"longitude": "",
"create_date": "2017-01-01",
"active_status": "Active",
"workshop_services": null,
"lubricants_available": "No",
"lubricant_products": null
},
{
"id": "142",
"user_id": "",
"store_id": null,
"updated_by": null,
"workshop_name": "Ali Automobile ",
"workshop_email": "",
"workshop_address": "Section -11, Block- D, Avenue-1 Plot-14, Mob: 01925920115",
"district": "Dhaka",
"thana": "Mirpur",
"post_code": "",
"contact_person": "Mohammad Ali",
"contact_number": "01925920115",
"alternative_number": "",
"service_type_car": "Car",
"service_type_bus": "",
"service_type_bike": "",
"workshop_photo_1": "",
"workshop_photo_2": "",
"workshop_photo_3": "",
"latitude": "",
"longitude": "",
"create_date": "2017-01-01",
"active_status": "Active",
"workshop_services": null,
"lubricants_available": "No",
"lubricant_products": null
}
]
}
Now my question is that how can I get each values of id, workshop_name etc? Please help me to parse this JSON data.
Thanks in advance.
Please refer to below code as reference:
using SimpleJSON;
var N = JSON.Parse(the_JSON_string);
var versionString = N["version"].Value; // versionString will be a string containing "1.0"
var versionNumber = N["version"].AsFloat; // versionNumber will be a
float containing 1.0
var name = N["data"]["sampleArray"][2]["name"];// name will be a string containing "sub object"
Here the JSON string (the_JSON_string) is as follows:
{
"version": "1.0",
"data": {
"sampleArray": [
"string value",
5,
{
"name": "sub object"
}
]
}
}
Note that according to our experience, SimpleJson works on both Android and iOS, and NewtonSoft does NOT work in some iOS devices. If your app is mobile app, you should not use NewtonJson.
Add Newtonsoft.Json from nuGet package manager to your solution.
Add reference inside the unity file
in server side serialize your list like: JsonConvert.SerializeObject(your object);
in client side do like this : JSON.Parse(your result)
I have a JSON file like below and I want to desterilize it to JSON Object how can I do it ? Thanks
{
"TOTAL": 2,
"PRODUCTS": [
{
"CODE": "T55",
"PRICE": 59.95,
"DESCRIPTION": "Ok"
},
{
"CODE": "T75",
"PRICE": 99.95,
"DESCRIPTION": "Not OK"
}]
You can refer this link for parsing from a file :
Get a JSON file from URL and display
And
You can use :
var obj = JSON.parse('{ "name":"Pawan", "age":24}');
Modern browsers support JSON.parse().
var json = [{
"TOTAL": 2,
"PRODUCTS": [
{
"CODE": "T55",
"PRICE": 59.95,
"DESCRIPTION": "Ok"
},
{
"CODE": "T75",
"PRICE": 99.95,
"DESCRIPTION": "Not OK"
}];
var arr_from_json = JSON.parse( json_string );
In browsers that don't, you can include the json2 library.
How can I post data in RestSharp ? I am very new to RestSharp and dont quite understand the process.
I am familar with Get Requests, which I have written API tests for with no problems.
Using the below example I want to post the Order Qty:
"name": "PostToCurrentBasket",
"class": [
"PostToCurrentBasket"
],
"method": "POST",
"href": "*",
"title": "Add Product to Current Basket",
"type": "application/json",
"fields": [
{
"name": "ProductId",
"type": "text",
"value": 101112,
"title": "Product ID"
},
{
"name": "Quantity",
"type": "number",
"value": 0,
"title": "Order Qty"
}
]
}
],
What I have so far:
var request = new RestRequest("baskets/current/", Method.POST);
Do I need to be using .AddBody and if so how do I use this correctly?
request.RequestFormat = DataFormat.Json; // If you want it to be json
request.AddBody(new { Name = "Foo", LastName = "Bar" }); // Any object that can be serialized
client.Execute(request);
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.