Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I have the following code :
string messageString1 = JsonConvert.SerializeObject(thisComputer);
var data = new { deviceid = "info1", devicetype = "info2", data = messageString1};
My goal is to add messageString1 into data .
thisComputer is a class and i know this part of the code works , because i got it working before , i'm just not being capable to get messageString1 into data.
I am not being able to insert data into data.I have tried several different ways but i still haven't figure it out.
EDIT:
the problem is that i am trying to send the JSON to azure IoThub and in fact the contents are getting trough and into IoT Hub but all the double quotes characters are now '\"' and that constitutes the problem .
EXAMPLE: If the data inside is :
{"data":"dataInfo"}
in Iot Hub i see :
{\"data\":\datainfo\"}
Thanks in advance.
Currently, you're JSON-encoding an object as a string, and then when you're sending the anonymous type instance to Cloud IoT, that's applying JSON encoding again.
It looks like you don't want the value of data to be a string - you want it to be the data from thisComputer. So just avoid that first level of encoding:
var data = new { deviceid = "info1", devicetype = "info2", data = thisComputer };
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last year.
Improve this question
So I have below code running, where I am calling an Api, which gives me result a Json Array which I am later querying in my code. The response, I get from the api is mostly constant and since it has SOME data, it takes few seconds to get the complete result. I would like to know, if I can store the result coming from api in some way in cache in order to make the whole processing part faster?
EDIT: below code is inside a Foreach loop
foreach (var did in myDeserializedClass)
{
if (did.id == matchedid)
{
url = "https://.../api/information/test";
var response = await Request(Stream.Null, url, "GET");
string message = await response.Content.ReadAsStringAsync();
var allcodes = JsonConvert.DeserializeObject<List<CoCode>>(message);
foreach(var cc in allcodes )
{....// rest of my code
You can absolutely use a memory cache, even Microsoft provide one which if possible also can be place in the api side for quicker lookups
https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.caching.memory.memorycache?view=dotnet-plat-ext-6.0
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
In my project; I have so many json file from web. And inside json file have campaign datas. But that data numbers is always changing. For example in first json it have 5 data and other json have 15. So I need create labels for that datas. For example if in the json file have 5 campaign data , i need create 5. İf it have 10 then i need create 10. Like this. So how can i make it ? I input json files and its works correctly i just need learn how can i create , position N label in xamarin ? Thanks for your help! <3
just create them and add them to some layout container, like this
var stack = new StackLayout();
foreach(var l in LabelData())
{
stack.Children.Add(new Label { Text = l.SomeProperty });
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I am trying to use the libphonenumber-csharp library and the FindNumbers feature. But I am unable to implement it properly. What am I doing wrong?
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
var a = phoneUtil.findNumbers("this is my phone number: (805) 527-9975", null);
Console.WriteLine(a);
Console.Write(phoneUtil.findNumbers("8055279975", "US"));
public Iterable<PhoneNumberMatch> findNumbers(CharSequence text, String defaultRegion);
I tried the code and I am getting this as the output:
java.lang.Iterable1[com.google.i18n.phonenumbers.PhoneNumberMatch]
java.lang.Iterable1[com.google.i18n.phonenumbers.PhoneNumberMatch]
Are you getting the same result? looking into the issue now and I'll let you know if I figure it out.
EDIT
I was able to figure it out!
The correct way to do it is like this:
string testString = "testing the ability to grab here: 345-365-567";
{
PhoneNumberUtil phoneUtil = PhoneNumberUtil.GetInstance();
PhoneNumber phoneNumber = phoneUtil.Parse(testString, "US");
//now from here you can do ahead and retrieve the number by calling upon phoneNumber.
Console.WriteLine(phoneNumber.NationalNumber);
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am making a game where people listen to determine whether something is black or white. I want to store how many times they got it correct and how many times they got it wrong in a database so they can see the old results.
What kind of database (like Sqlite) should I use? How should I save this information and display it later?
You can use BinarySerializtion, XMLSerialization,......
so first create a class:
[Serializable]
public class Result
{
Public int TimesRight {get;set;}
Public int TimesWrong {get;set;}
}
now in your game:
Result result = new Result();
result.TimesRight = x; //value of times right
result.TimesWrong = y; //value of times wrong
Now choose the way you want to save it, here are some references for Binary and XML serialization:
Binary Serialization
XML Serialization
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
This is my JObject.Parse string.
{"topic":{"account_id":190884,"created_at":"2015-01-31T16:35:59+05:00","delta":true,"forum_id":5000225377,"hits":0,"id":5000025527,"import_id":null,"last_post_id":5000040596,"locked":false,"merged_topic_id":null,"posts_count":0,"published":true,"replied_at":"2015-01-31T16:35:59+05:00","replied_by":5005399997,"stamp_type":null,"sticky":0,"title":"I want use API of Freshdesk.","updated_at":"2015-01-31T16:35:59+05:00","user_id":5005399997,"user_votes":0,"posts":[{"account_id":190884,"answer":false,"body":" I want to use API of Freshdesk to get forums of Freshdesk. I want to access users and posts from different Forums and show that data in my Application. I want to develop C# console Application.\u00a0 Anyone please help me. \r\n","body_html":"\u003Cp\u003EI want to use API of Freshdesk to get forums of Freshdesk. I want to access users and posts from different Forums and show that data in my Application. I want to develop C# console Application.\u00a0\u003C/p\u003E\u003Cp\u003EAnyone please help me.\u003C/p\u003E\r\n","created_at":"2015-01-31T16:35:59+05:00","forum_id":5000225377,"id":5000040596,"import_id":null,"published":true,"spam":null,"topic_id":5000025527,"trash":false,"updated_at":"2015-01-31T16:35:59+05:00","user_id":5005399997}]}}
I want to get values of (posts) from this string in C#. Anyone can help me how i can get values of posts from this string.
Use Newtonsoft's Json.net
https://www.nuget.org/packages/Newtonsoft.Json/
It is an easy to use library:
Example:
string json = #"{
'Name': 'Bad Boys',
'ReleaseDate': '1995-4-7T00:00:00',
'Genres': [
'Action',
'Comedy'
]
}";
Movie m = JsonConvert.DeserializeObject<Movie>(json);
string name = m.Name;
var s=<json_string>;
var firstPost = JObject.Parse(s)["topic"]["posts"][0];
string postBody = (string)firstPost["body"];