Click here to Skip to main content
15,881,852 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
Questionnot able to Deserialize json signature lines Pin
ven7534-Feb-14 18:36
ven7534-Feb-14 18:36 
AnswerRe: not able to Deserialize json signature lines Pin
Richard Deeming5-Feb-14 2:57
mveRichard Deeming5-Feb-14 2:57 
GeneralRe: not able to Deserialize json signature lines Pin
ven7535-Feb-14 5:17
ven7535-Feb-14 5:17 
GeneralRe: not able to Deserialize json signature lines Pin
Richard Deeming5-Feb-14 5:35
mveRichard Deeming5-Feb-14 5:35 
GeneralRe: not able to Deserialize json signature lines Pin
ven7535-Feb-14 6:11
ven7535-Feb-14 6:11 
GeneralRe: not able to Deserialize json signature lines Pin
Richard Deeming5-Feb-14 6:50
mveRichard Deeming5-Feb-14 6:50 
GeneralRe: not able to Deserialize json signature lines Pin
ven7535-Feb-14 7:18
ven7535-Feb-14 7:18 
GeneralRe: not able to Deserialize json signature lines Pin
Richard Deeming5-Feb-14 8:01
mveRichard Deeming5-Feb-14 8:01 
OK, that makes more sense. There's still the slight issue that the JSON is using floating-point numbers but the DrawLine method expects integers, but you can probably ignore that for now.

You'll still need to deserialize to the class I posted previously, but you can use an iterator method to construct the sequence of SignatureLine objects from the data:
C#
private sealed class SignatureLine
{
    public int lx { get; set; }
    public int ly { get; set; }
    public int mx { get; set; }
    public int my { get; set; }
}

private class Signature
{
    public List<List<List<double>>> lines { get; set; }
    
    public IEnumerable<SignatureLine> SignatureLines
    {
        get
        {
            foreach (List<List<double>> stroke in lines)
            {
                if (stroke.Count == 1) continue;
                
                List<double> lastPoint = stroke[0];
                Debug.Assert(lastPoint.Count == 2);
                
                foreach (List<double> point in stroke.Skip(1))
                {
                    Debug.Assert(point.Count == 2);
                    
                    // For now, just round the floating point values to the nearest integer:
                    yield return new SignatureLine
                    {
                        lx = (int)Math.Round(lastPoint[0]),
                        ly = (int)Math.Round(lastPoint[1]),
                        mx = (int)Math.Round(point[0]),
                        my = (int)Math.Round(point[1])
                    };
                    
                    lastPoint = point;
                }
            }
        }
    }
}

...

var serializer = new JavaScriptSerializer();
var signature = serializer.Deserialize<Signature>(json);
foreach (SignatureLine line in signature.SignatureLines)
{
   signatureGraphic.DrawLine(pen, line.lx, line.ly, line.mx, line.my);
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: not able to Deserialize json signature lines Pin
ven7535-Feb-14 16:09
ven7535-Feb-14 16:09 
GeneralRe: not able to Deserialize json signature lines Pin
Richard Deeming6-Feb-14 1:37
mveRichard Deeming6-Feb-14 1:37 
GeneralRe: not able to Deserialize json signature lines Pin
ven7536-Feb-14 6:54
ven7536-Feb-14 6:54 
GeneralRe: not able to Deserialize json signature lines Pin
Richard Deeming6-Feb-14 8:56
mveRichard Deeming6-Feb-14 8:56 
GeneralRe: not able to Deserialize json signature lines Pin
ven7536-Feb-14 16:18
ven7536-Feb-14 16:18 
GeneralRe: not able to Deserialize json signature lines Pin
ven7536-Feb-14 21:34
ven7536-Feb-14 21:34 
GeneralRe: not able to Deserialize json signature lines Pin
ven7537-Feb-14 7:03
ven7537-Feb-14 7:03 
GeneralRe: not able to Deserialize json signature lines Pin
Richard Deeming10-Feb-14 1:27
mveRichard Deeming10-Feb-14 1:27 
Question3 layers architecture & MVC Pin
kryptong4-Feb-14 3:20
kryptong4-Feb-14 3:20 
AnswerRe: 3 layers architecture & MVC Pin
Eddy Vluggen4-Feb-14 7:55
professionalEddy Vluggen4-Feb-14 7:55 
GeneralRe: 3 layers architecture & MVC Pin
kryptong4-Feb-14 8:08
kryptong4-Feb-14 8:08 
GeneralRe: 3 layers architecture & MVC Pin
Eddy Vluggen5-Feb-14 0:30
professionalEddy Vluggen5-Feb-14 0:30 
AnswerRe: 3 layers architecture & MVC Pin
Pete O'Hanlon4-Feb-14 8:28
mvePete O'Hanlon4-Feb-14 8:28 
AnswerRe: 3 layers architecture & MVC Pin
CoderPanda5-Feb-14 6:56
professionalCoderPanda5-Feb-14 6:56 
QuestionGood GC configuration for Web services Pin
Pingala31-Jan-14 11:36
Pingala31-Jan-14 11:36 
AnswerRe: Good GC configuration for Web services Pin
Dave Kreskowiak31-Jan-14 11:58
mveDave Kreskowiak31-Jan-14 11:58 
AnswerRe: Good GC configuration for Web services Pin
CoderPanda5-Feb-14 7:23
professionalCoderPanda5-Feb-14 7:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.