yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
Quintiq file version 2.0
#parent: #root
StaticMethod JSONToNamedValue (
  JSON json
) const remote as owning NamedValueTree
{
  TextBody:
  [*
    result := NamedValueTree::Create();
    
    // Read the name
    name := json.Get( attribute( NamedValue, Name ).Name() ).GetString();
    
    result.Root( name );
    nv := result.Root();
    
    // Read the value
    if( json.Has( typeof( Value ).Name() ) )
    {
      json_value := json.Get( typeof( Value ).Name() );
      type := json_value.Get( typeof( Type ).Name() ).GetString();
      payload := json_value.Get( typeof( Value ).Name() ).GetString();
      if( type = typeof( BinaryValue ).Name() )
      {
        nv.SetValue( BinaryValue::FromHexString( payload ) );
      }
      else if( type = typeof( Boolean ).Name() )
      {
        nv.SetValue( StringToBoolean::ISOConverter().Convert( payload ) );
      }
      else if( type = typeof( Char ).Name() )
      {
        nv.SetValue( StringToChar::ISOConverter().Convert( payload ) );
      }
      else if( type = typeof( Date ).Name() )
      {
        nv.SetValue( StringToDate::ISOConverter().Convert( payload ) );
      }
      else if( type = typeof( DateTime ).Name() )
      {
        nv.SetValue( StringToDateTime::ISOConverter().Convert( payload ) );
      }
      else if( type = typeof( Duration ).Name() )
      {
        nv.SetValue( StringToDuration::ISOConverter().Convert( payload ) );
      }
      else if( type = typeof( Key ).Name() )
      {
        nv.SetValue( StringToKey::ISOConverter().Convert( payload ) );
      }
      else if( type = typeof( Number ).Name() )
      {
        nv.SetValue( StringToNumber::ISOConverter().Convert( payload ) );
      }
      else if( type = typeof( Real ).Name() )
      {
        nv.SetValue( StringToReal::ISOConverter().Convert( payload ) );
      }
      else if( type = typeof( String ).Name() )
      {
        nv.SetValue( payload );
      }
    }
    
    // Read the children
    children := json.Get( method( NamedValue, Children ).Name() );
    
    for( i := 0; i < children.Size(); i++ )
    {
      nvt := LibOpt_Utility::JSONToNamedValue( children.Get( i ) );
      nvt.Root().Move( nv, true );
    }
    
    return & result;
  *]
}