Click here to Skip to main content
15,439,290 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I get a message from a server on my console. this message is in json :
[{"timestamp":1613491157.2313604,"data":{"coordinatesType":1,"tagData":{"sensors":[{"name":"CUSTOM_PAYLOAD","value":""}],"blinkIndex":135013},"coordinates":{"y":470,"x":6706,"z":1000},"anchorData":[{"anchorId":"57164","tagId":"26925","rss":-94.07},{"anchorId":"49218","tagId":"26925","rss":-81.79},{"anchorId":"17671","tagId":"26925","rss":-86.1},{"anchorId":"4226","tagId":"26925","rss":-85.23},{"anchorId":"22367","tagId":"26925","rss":-88.93},{"anchorId":"24660","tagId":"26925","rss":-81.5}],"metrics":{"rates":{"update":41.76,"success":42.04,"packetLoss":0.23},"latency":28},"extras":{"version":"0.1","zones":[]}},"version":"1.4","tagId":"26925","success":true}]
[{"timestamp":1613491157.2551506,"data":{"coordinatesType":1,"tagData":{"sensors":[{"name":"CUSTOM_PAYLOAD","value":""}]{"blinkIndex":135014},"coordinates":{"y":470,"x":6707,"z":1000},"anchorData":[{"anchorId":"22367","tagId":"26925","rss":-88.35},{"anchorId":"17671","tagId":"26925","rss":-85.64},{"anchorId":"49218","tagId":"26925","rss":-81.67},{"anchorId":"24660","tagId":"26925","rss":-81.53},{"anchorId":"4226","tagId":"26925","rss":-85.35}],"metrics":{"rates":{"update":42.03,"success":42.32,"packetLoss":0.23},"latency":21},"extras":{"version":"0.1","zones":[]}},"version":"1.4","tagId":"26925","success":true}]
[{"timestamp":1613491157.2503972,"data":{"coordinatesType":1,"tagData":{"sensors":[{"name":"CUSTOM_PAYLOAD","value":""}]{"blinkIndex":125687},"coordinates":{"y":710,"x":8067,"z":1000},"anchorData":[{"anchorId":"49218","tagId":"26884","rss":-85.64},{"anchorId":"57164","tagId":"26884","rss":-87.81},{"anchorId":"4226","tagId":"26884","rss":-84.19},{"anchorId":"22367","tagId":"26884","rss":-85.38},{"anchorId":"17671","tagId":"26884","rss":-87.81},{"anchorId":"24660","tagId":"26884","rss":-81.88}],"metrics":{"rates":{"update":10.42,"success":10.49,"packetLoss":0.09},"latency":27},"extras":{"version":"0.1","zones":[]}},"version":"1.4","tagId":"26884","success":true}]
[{"timestamp":1613491157.2789102,"data":{"coordinatesType":1,"tagData":{"sensors":[{"name":"CUSTOM_PAYLOAD","value":""}]{"blinkIndex":135015},"coordinates":{"y":470,"x":6707,"z":1000},"anchorData":[{"anchorId":"49218","tagId":"26925","rss":-82.08},{"anchorId":"17671","tagId":"26925","rss":-85.91},{"anchorId":"24660","tagId":"26925","rss":-82.03},{"anchorId":"4226","tagId":"26925","rss":-84.9},{"anchorId":"22367","tagId":"26925","rss":-88.94},{"anchorId":"57164","tagId":"26925","rss":-94.74}],"metrics":{"rates":{"update":41.79,"success":42.07,"packetLoss":0.23},"latency":27},"extras":{"version":"0.1","zones":[]}},"version":"1.4","tagId":"26925","success":true}]
[{"timestamp":1613491157.3026805,"data":{"coordinatesType":1,"tagData":{"sensors":[{"name":"CUSTOM_PAYLOAD","value":""}]{"blinkIndex":135016},"coordinates":{"y":469,"x":6708,"z":1000},"anchorData":[{"anchorId":"57164","tagId":"26925","rss":-95.04},{"anchorId":"49218","tagId":"26925","rss":-81.7},{"anchorId":"17671","tagId":"26925","rss":-85.79},{"anchorId":"4226","tagId":"26925","rss":-85.04},{"anchorId":"22367","tagId":"26925","rss":-88.2},{"anchorId":"24660","tagId":"26925","rss":-81.72}],"metrics":{"rates":{"update":42.03,"success":42.33,"packetLoss":0.23},"latency":21},"extras":{"version":"0.1","zones":[]}},"version":"1.4","tagId":"26925","success":true}]
[{"timestamp":1613491157.326472,"data":{"coordinatesType":1,"tagData":{"sensors":[{"name":"CUSTOM_PAYLOAD","value":""}]{"blinkIndex":135017},"coordinates":{"y":470,"x":6711,"z":1000},"anchorData":[{"anchorId":"57164","tagId":"26925","rss":-95.17},{"anchorId":"49218","tagId":"26925","rss":-81.6},{"anchorId":"4226","tagId":"26925","rss":-85.01},{"anchorId":"22367","tagId":"26925","rss":-88.47},{"anchorId":"17671","tagId":"26925","rss":-86.66},{"anchorId":"24660","tagId":"26925","rss":-81.44}],"metrics":{"rates":{"update":41.81,"success":42.1,"packetLoss":0.23},"latency":26},"extras":{"version":"0.1","zones":[]}},"version":"1.4","tagId":"26925","success":true}]
[{"timestamp":1613491157.3456326,"data":{"coordinatesType":1,"tagData":{"sensors":[{"name":"CUSTOM_PAYLOAD","value":""}]{"blinkIndex":125688},"coordinates":{"y":717,"x":8072,"z":1000},"anchorData":[{"anchorId":"57164","tagId":"26884","rss":-87.32},{"anchorId":"49218","tagId":"26884","rss":-85.5},{"anchorId":"17671","tagId":"26884","rss":-87.03},{"anchorId":"4226","tagId":"26884","rss":-84.28},{"anchorId":"22367","tagId":"26884","rss":-85.3},{"anchorId":"24660","tagId":"26884","rss":-82.14}],"metrics":{"rates":{"update":10.46,"success":10.53,"packetLoss":0.09},"latency":24},"extras":{"version":"0.1","zones":[]}},"version":"1.4","tagId":"26884","success":true}]
[{"timestamp":1613491157.3502278,"data":{"coordinatesType":1,"tagData":{"sensors":[{"name":"CUSTOM_PAYLOAD","value":""}]{"blinkIndex":135018},"coordinates":{"y":469,"x":6711,"z":1000},"anchorData":[{"anchorId":"57164","tagId":"26925","rss":-93.17},{"anchorId":"49218","tagId":"26925","rss":-81.97},{"anchorId":"17671","tagId":"26925","rss":-86.08},{"anchorId":"4226","tagId":"26925","rss":-85.12},{"anchorId":"22367","tagId":"26925","rss":-88.52},{"anchorId":"24660","tagId":"26925","rss":-81.21}],"metrics":{"rates":{"update":42.03,"success":42.33,"packetLoss":0.23},"latency":21},"extras":{"version":"0.1","zones":[]}},"version":"1.4","tagId":"26925","success":true}]
[{"timestamp":1613491157.3740551,"data":{"coordinatesType":1,"tagData":{"sensors":[{"name":"CUSTOM_PAYLOAD","value":""}]{"blinkIndex":135019},"coordinates":{"y":469,"x":6711,"z":1000},"anchorData":[{"anchorId":"57164","tagId":"26925","rss":-93.75},{"anchorId":"49218","tagId":"26925","rss":-81.94},{"anchorId":"4226","tagId":"26925","rss":-84.51},{"anchorId":"22367","tagId":"26925","rss":-87.66},{"anchorId":"17671","tagId":"26925","rss":-85.54},{"anchorId":"24660","tagId":"26925","rss":-81.58}],"metrics":{"rates":{"update":41.76,"success":42.05,"packetLoss":0.23},"latency":27},"extras":{"version":"0.1","zones":[]}},"version":"1.4","tagId":"26925","success":true}]
[{"timestamp":1613491157.3977597,"data":{"coordinatesType":1,"tagData":{"sensors":[{"name":"CUSTOM_PAYLOAD","value":""}]{"blinkIndex":135020},"coordinates":{"y":469,"x":6712,"z":1000},"anchorData":[{"anchorId":"57164","tagId":"26925","rss":-93.26},{"anchorId":"49218","tagId":"26925","rss":-81.72},{"anchorId":"17671","tagId":"26925","rss":-85.73},{"anchorId":"4226","tagId":"26925","rss":-84.73},{"anchorId":"22367","tagId":"26925","rss":-87.47},{"anchorId":"24660","tagId":"26925","rss":-81.64}],"metrics":{"rates":{"update":42,"success":42.3,"packetLoss":0.23},"latency":21},"extras":{"version":"0.1","zones":[]}},"version":"1.4","tagId":"26925","success":true}]
[{"timestamp":1613491157.4215534,"data":{"coordinatesType":1,"tagData":{"sensors":[{"name":"CUSTOM_PAYLOAD","value":""}]{"blinkIndex":135021},"coordinates":{"y":469,"x":6713,"z":1000},"anchorData":[{"anchorId":"49218","tagId":"26925","rss":-81.92},{"anchorId":"57164","tagId":"26925","rss":-93.05},{"anchorId":"4226","tagId":"26925","rss":-85.05},{"anchorId":"22367","tagId":"26925","rss":-87.77},{"anchorId":"17671","tagId":"26925","rss":-85.98},{"anchorId":"24660","tagId":"26925","rss":-81.43}],"metrics":{"rates":{"update":41.81,"success":42.1,"packetLoss":0.23},"latency":26},"extras":{"version":"0.1","zones":[]}},"version":"1.4","tagId":"26925","success":true}]
[{"timestamp":1613491157.440852,"data":{"coordinatesType":1,"tagData":{"sensors":[{"name":"CUSTOM_PAYLOAD","value":""}]{"blinkIndex":125689},"coordinates":{"y":717,"x":8071,"z":1000},"anchorData":[{"anchorId":"57164","tagId":"26884","rss":-87.41},{"anchorId":"49218","tagId":"26884","rss":-85.61},{"anchorId":"4226","tagId":"26884","rss":-85.05},{"anchorId":"22367","tagId":"26884","rss":-85.71},{"anchorId":"17671","tagId":"26884","rss":-86.99},{"anchorId":"24660","tagId":"26884","rss":-83.18}],"metrics":{"rates":{"update":10.51,"success":10.59,"packetLoss":0.09},"latency":18},"extras":{"version":"0.1","zones":[]}},"version":"1.4","tagId":"26884","success":true}]
[{"timestamp":1613491157.4452944,"data":{"coordinatesType":1,"tagData":{"sensors":[{"name":"CUSTOM_PAYLOAD","value":""}]{"blinkIndex":135022},"coordinates":{"y":470,"x":6713,"z":1000},"anchorData":[{"anchorId":"57164","tagId":"26925","rss":-92.89},{"anchorId":"49218","tagId":"26925","rss":-81.8},{"anchorId":"17671","tagId":"26925","rss":-85.73},{"anchorId":"4226","tagId":"26925","rss":-85.15},{"anchorId":"22367","tagId":"26925","rss":-87.72},{"anchorId":"24660","tagId":"26925","rss":-81.28}],"metrics":{"rates":{"update":42.04,"success":42.34,"packetLoss":0.23},"latency":20},"extras":{"version":"0.1","zones":[]}},"version":"1.4","tagId":"26925","success":true}]
[{"timestamp":1613491157.4692545,"data":{"coordinatesType":1,"tagData":{"sensors":[{"name":"CUSTOM_PAYLOAD","value":""}]{"blinkIndex":135023},"coordinates":{"y":470,"x":6713,"z":1000},"anchorData":[{"anchorId":"49218","tagId":"26925","rss":-82},{"anchorId":"57164","tagId":"26925","rss":-93.94},{"anchorId":"4226","tagId":"26925","rss":-84.88},{"anchorId":"22367","tagId":"26925","rss":-88.4},{"anchorId":"17671","tagId":"26925","rss":-86.13},{"anchorId":"24660","tagId":"26925","rss":-81.68}],"metrics":{"rates":{"update":41.84,"success":42.13,"packetLoss":0.23},"latency":25},"extras":{"version":"0.1","zones":[]}},"version":"1.4","tagId":"26925","success":true}]
[{"timestamp":1613491157.4928694,"data":{"coordinatesType":1,"tagData":{"sensors":[{"name":"CUSTOM_PAYLOAD","value":""}]{"blinkIndex":135024},"coordinates":{"y":470,"x":6713,"z":1000},"anchorData":[{"anchorId":"57164","tagId":"26925","rss":-92.91},{"anchorId":"49218","tagId":"26925","rss":-81.83},{"anchorId":"17671","tagId":"26925","rss":-86.54},{"anchorId":"4226","tagId":"26925","rss":-85.08},{"anchorId":"22367","tagId":"26925","rss":-87.89},{"anchorId":"24660","tagId":"26925","rss":-81.73}],"metrics":{"rates":{"update":41.58,"success":41.87,"packetLoss":0.23},"latency":31},"extras":{"version":"0.1","zones":[]}},"version":"1.4","tagId":"26925","success":true}]


What I have tried:

C#
IEnumerabledeserialize.Example> todo = JsonConvert.DeserializeObjectListdeserialize.Example>>(strresulttest);


here are my classes:
C#
class jsondeserialize
        {



            public class Sensor
            {
                public string name { get; set; }
                public string value { get; set; }
            }

            public class TagData
            {
                public IList<Sensor> sensors { get; set; }
                public int blinkIndex { get; set; }
            }

            public class Coordinates
            {
                public int y { get; set; }
                public int x { get; set; }
                public int z { get; set; }
            }

            public class AnchorData
            {
                public string anchorId { get; set; }
                public string tagId { get; set; }
                public double rss { get; set; }
            }

            public class Rates
            {
                public double update { get; set; }
                public double success { get; set; }
                public double packetLoss { get; set; }
            }

            public class Metrics
            {
                public Rates rates { get; set; }
                public int latency { get; set; }
            }

            public class Extras
            {
                public string version { get; set; }
                public IList<object> zones { get; set; }
            }

            public class Data
            {
                public int coordinatesType { get; set; }
                public TagData tagData { get; set; }
                public Coordinates coordinates { get; set; }
                public IList<AnchorData> anchorData { get; set; }
                public Metrics metrics { get; set; }
                public Extras extras { get; set; }
            }

            public class Example
            {
                public double timestamp { get; set; }
                public Data data { get; set; }
                public string version { get; set; }
                public string tagId { get; set; }
                public bool success { get; set; }
            }
        }
    }



I have an exception
Newtonsoft.Json.JsonReaderException: 'Additional text encountered after finished reading JSON content: [. Path '', line 2, position 0.'). Can you help me?
Posted
Updated 17-Feb-21 10:50am
v2

1 solution

Your data isn't valid JSON as it stands: it's a collection of valid JSON elements separated by newlines.
If I cut out loads of teh data to demonstate what I mean, this is still invalid:
[{"timestamp":1613491157.2313604,"data":{"coordinatesType":1}}]
[{"timestamp":1613491157.2551506,"data":{"coordinatesType":1}}]{
But if I add "surrounding" JSON, it becomes readable:
[[{"timestamp":1613491157.2313604,"data":{"coordinatesType":1}}],
 [{"timestamp":1613491157.2551506,"data":{"coordinatesType":1}}]]

You need to either spilt your data into individual lines and process each as separate JSON, or add the required odds and ends to get valid JSON from it.

Or go back to where you got it from, and ask them why it's like that ... :laugh:
 
Share this answer
 
Comments
Kenneth Haugland 17-Feb-21 11:58am    
"Or go back to where you got it from, and ask them why it's like that ... :laugh:" I tried this,and they said: Whats your problem. I can read the json just fine...
Mamadou Aliou DIALLO 17-Feb-21 14:08pm     CRLF
i try to Deserialize juste one line it works but when i try to deserialize the next lines , i meet this except: Newtonsoft.Json.JsonReaderException: 'Additional text encountered after finished reading JSON content: [. Path '', line 2, position 0.that's the problem Improve solution Permalink Posted 1 sec ago
OriginalGriff 17-Feb-21 15:02pm     CRLF
Yes. Because it's not valid JSON data with two lumps of valid data rammed together. Each line is fine, but concatenate them and you get invalid data. Just like you do with English: The cat sat on the mat. Is fine. The cat sat on the mat chicken is not a fruit. Is not sensible. Convert it to two different sentences and it works: The cat sat on the mat. Chicken is not a fruit. Read what I said originally ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900