Browsing 7239 questions and answers with Jon Skeet
I have following code
dateTimeFormat = ISODateTimeFormat.dateTimeNoMillis()
and i use dateTimeFormat below
public static String print(Date value) {
return...
In all date instances has the same time zone Europe/Moscow
A Date instance doesn't have a time zone - it's just an instant in time. But you should probably specify the time zone for your formatter, e.g.
dateTimeFormat =...
more
4/22/2015 2:55:45 PM
I have been trying to create a LINQ statement that will join 3 tables with left outer joins. When I try to run the code, I am receiving a 'System.NullReferenceException' error.
...
Just handle item.Language being null in your view:
<p>@item.Language == null ? "" : @item.Language.LanguageSpoken</p>
In C# 6 this is even simpler:
<p>@item.Language?.LanguageSpoken</p>
(Assuming that null...
more
4/22/2015 2:39:38 PM
I have the following json string
[["{\"object\":\"user\",\"entry\":[{\"uid\":\"823602904340066\",\"id\":\"823602904340066\",\"time\":1429276535,\"changed_fields\":[\"feed\"]}]}"],["{\"object\":\"user\",\"entry\":[{\"uid\":\"10152579760466676\",\"id\":\"10152579760466676\",\"time\":1429278530,\"changed_fields\":[\"feed\"]}]}"],["{\"object\":\"user\",\"entry\":[{\"uid\":\"10203227586595390\",\"id\":\"10203227586595390\",\"time\":1429278537,\"changed_fields\":[\"feed\"]}]}"],["{\"object\":\"user\",\"entry\":[{\"uid\":\"10203227586595390\",\"id\":\"10203227586595390\",\"time\":1429278521,\"changed_fields\":[\"feed\"]}]}"]]
JsonConvert.DeserializeObject<List<RootObject>>(jsonData);
When rrying to convert this into json object with Netwonsoft.json ,I am get getting error "Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'Model.RootObject' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly."
I am using the following classes
public class RootObject
{
public List<Entry> entry;
}
public class Entry
{
public string uid;
public string id { get; set; }
public int time { get; set; }
public List<string> changed_fields { get; set; }
}
Can some please tell where am i getting it wrong ?
Your JSON doesn't contain any RootObject objects - it just contains strings. You've got an array of arrays of strings, where each "nested" array just contains a single string, and each string is the JSON representation of a RootObject.
If...
more
4/22/2015 8:47:03 AM
I have a problem with ToList() method and basically I'm trying to make a function that will return a var linq query convert to a list and here the the function.
...
You're calling Single(), which means you've got one result. ToList() is an extension method on IEnumerable<T>.
If you want to create a list with just that one element, you could write:
return new List<UsersTabPage> { firstone...
more
4/21/2015 7:29:06 PM
Is there a class called 'main' or something that java looks for in your project?
If it finds it, does the compiler take the 'main.class' as a starting point for compilation?
I...
At compilation time, it doesn't usually matter - you just specify all the source files you want to compile. (You can specify a subset and the compiler will find other source files it needs, but it's better to specify everything you want...
more
4/21/2015 4:06:27 PM
public class one
{
public static void main(String [] args)
{
}
public static int vowels( String s )
{
int countA = 0; int countE = 0; int...
You can only return a single value from a method call. However, that value can be an array or a collection.
Two options to consider:
Change your method to accept a second parameter of "the character to count" occurrences of, and call it...
more
4/21/2015 2:50:35 PM
I'm seeing what appears to my novice eyes as conflicting conventions in Java, when it comes to declaring instance variables. For example, a classic bank account instance variable...
Why is this second syntax ok when it looks like it deviates wildly from the first?
It doesn't deviate at all from the first.
Part First example Second example
Access modifier private ...
more
4/21/2015 12:35:56 PM
The below code might look odd in functionality. This is because this is a simplified presentation of something bigger.
I have a class named Person and the person has 1 property...
My goal with ClassRoom(Person person) is that, if the Person is null, ClassRoom() is called and if it's not null ClassRoom(Person person, string name) is called.
You can't do that, basically. You can't decide which constructor to...
more
4/21/2015 10:14:34 AM
In this fiddle, we are assigning a static field to an instance field. When we change the static one, the instance one still has the initial value. Why is that? We thought that...
In this fiddle, we are assigning a static field to an instance field.
Right. That copies the current value of the static field to the instance field. It doesn't tie the variables together forever - it just copies the current...
more
4/21/2015 5:54:39 AM
I have need to return the byte array for the ByteArrayOutputStream from the called method. I see two ways to achieve the same thing: firstly to return ByteArrayOutputStream &...
There's another alternative: return an InputStream. The idea is presumably that you're returning the data resulting from the operation. As such, returning an output stream seems very odd to me. To return data, you'd normally either return...
more
4/21/2015 5:51:33 AM