Sujet : Re: tdom encoding
De : gregor.ebbing (at) *nospam* gmx.de (greg)
Groupes : comp.lang.tclDate : 17. Dec 2024, 03:13:14
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vjqmnq$1dblc$1@dont-email.me>
References : 1
User-Agent : Mozilla Thunderbird
Am 17.12.24 um 01:01 schrieb saito:
I am trying to see why tdom is failing on this json snippet.
package req tdom
set x {{"name":"Jeremi"}}
dom parse -json $x
==> error "JSON syntax error" at position 15
"{"name":"Jeremi <--Error-- "}"
If it doesn't get removed by the newsgroup editors, there is a weird character at the very end of x. It looks almost like "[]" but it is not. When you edit it, it acts as if it has multiple characters in it.
Another problem is that tdom man page talks about a command "dom setResultEncoding ?encodingName?" but trying it results in an unknown command error.
Hello,
The unknown character is 007 or BELL.
Probably not allowed as a char in string.
Instead: \u0007
Gregor
package req tdom
proc chr c {
if {[string length $c] > 1 } {
error "chr: arg should be a single char"
}
set v 0
scan $c %c v
return $v
}
# Check character types and provide additional information
proc charInfo char {
if {[string is control $char]} {
return "control character"
} elseif {[string is space $char]} {
return "space character"
} elseif {[string is digit $char]} {
return "digit character"
} elseif {[string is lower $char]} {
return "lowercase alphabetic character"
} elseif {[string is upper $char]} {
return "uppercase alphabetic character"
} elseif {[string is punct $char]} {
return "punctuation character"
} elseif {[string is graph $char]} {
return "graphical character"
} elseif {[string is print $char]} {
return "printable character"
} else {
return "unknown character type"
}
}
proc infochar {x} {
puts $x
set i 0
while {$i<[string length $x]} {
set c [string index $x $i]
puts "$i is $c [charInfo $c] [chr $c] "
incr i
}
}
set x {{"name":"Jeremi"}}
infochar $x
catch {dom parse -json $x} mess
puts "mess: $mess"
set x {{"name":"Jeremi\u0007"}}
set doc [dom parse -json $x]
puts [$doc asXML]