1

The url is : http://reportguru.webdenza.com/vdetect-pro-2/api.php?q={%22svc%22:%22avl_evts%22,%22app%22:%22hst%22,%22sid%22:%22e93c3c3fbc1e3add3a518ca9d3f28d65%22}

The url contains the following json string.

{
"tm": 1395378731,
"events": [
    {
        "i": 828930,
        "t": "u",
        "d": {
            "prms": {
                "battery_charge": {
                    "v": 0,
                    "ct": 1395374632,
                    "at": 1395374632
                },
                "in": {
                    "v": 0,
                    "ct": 1395374632,
                    "at": 1395374632
                },
                "in1": {
                    "v": 0,
                    "ct": 1395374632,
                    "at": 1395374632
                },
                "in10": 1395374632,
                "in11": 1395374632,
                "in12": 1395374632,
                "in13": 1395374632,
                "in14": 1395374632,
                "in15": 1395374632,
                "in16": 1395374632,
                "in17": 1395374632,
                "in18": 1395374632,
                "in19": 1395374632,
                "in2": 1395374632,
                "in20": 1395374632,
                "in21": 1395374632,
                "in22": 1395374632,
                "in23": 1395374632,
                "in24": 1395374632,
                "in25": 1395374632,
                "in26": 1395374632,
                "in27": 1395374632,
                "in28": 1395374632,
                "in29": 1395374632,
                "in3": 1395374632,
                "in30": 1395374632,
                "in31": 1395374632,
                "in32": 1395374632,
                "in4": 1395374632,
                "in5": 1395374632,
                "in6": 1395374632,
                "in7": 1395374632,
                "in8": 1395374632,
                "in9": 1395374632,
                "param179": 1395374632,
                "param180": 1395374632,
                "param250": {
                    "v": 0,
                    "ct": 1395374632,
                    "at": 1395374632
                },
                "posinfo": {
                    "v": {
                        "y": 24.9639728,
                        "x": 55.202432,
                        "z": 57,
                        "c": 0,
                        "sc": 9
                    },
                    "ct": 1395374632,
                    "at": 1395374632
                },
                "speed": {
                    "v": 0,
                    "ct": 1395374632,
                    "at": 1395374632
                }
            }
        }
    },
    {
        "i": 828930,
        "t": "m",
        "d": {
            "t": 1395374507,
            "f": 3,
            "tp": "ud",
            "pos": {
                "y": 24.9655744,
                "x": 55.2024064,
                "z": 25,
                "s": 7,
                "c": 164,
                "sc": 10
            },
            "i": 1,
            "p": {
                "battery_charge": 1,
                "param179": 0,
                "param180": 0
            }
        }
    },
    {
        "i": 828930,
        "t": "u",
        "d": {
            "prms": {
                "battery_charge": {
                    "v": 0,
                    "ct": 1395374632,
                    "at": 1395374632
                },
                "in": {
                    "v": 0,
                    "ct": 1395374632,
                    "at": 1395374632
                },
                "in1": {
                    "v": 0,
                    "ct": 1395374632,
                    "at": 1395374632
                },
                "in10": 1395374632,
                "in11": 1395374632,
                "in12": 1395374632,
                "in13": 1395374632,
                "in14": 1395374632,
                "in15": 1395374632,
                "in16": 1395374632,
                "in17": 1395374632,
                "in18": 1395374632,
                "in19": 1395374632,
                "in2": 1395374632,
                "in20": 1395374632,
                "in21": 1395374632,
                "in22": 1395374632,
                "in23": 1395374632,
                "in24": 1395374632,
                "in25": 1395374632,
                "in26": 1395374632,
                "in27": 1395374632,
                "in28": 1395374632,
                "in29": 1395374632,
                "in3": 1395374632,
                "in30": 1395374632,
                "in31": 1395374632,
                "in32": 1395374632,
                "in4": 1395374632,
                "in5": 1395374632,
                "in6": 1395374632,
                "in7": 1395374632,
                "in8": 1395374632,
                "in9": 1395374632,
                "param179": 1395374632,
                "param180": 1395374632,
                "param250": {
                    "v": 0,
                    "ct": 1395374632,
                    "at": 1395374632
                },
                "posinfo": {
                    "v": {
                        "y": 24.9639728,
                        "x": 55.202432,
                        "z": 57,
                        "c": 0,
                        "sc": 9
                    },
                    "ct": 1395374632,
                    "at": 1395374632
                },
                "speed": {
                    "v": 0,
                    "ct": 1395374632,
                    "at": 1395374632
                }
            }
        }
    },
    {
        "i": 828930,
        "t": "m",
        "d": {
            "t": 1395374504,
            "f": 3,
            "tp": "ud",
            "pos": {
                "y": 24.9656512,
                "x": 55.2023744,
                "z": 24,
                "s": 17,
                "c": 130,
                "sc": 10
            },
            "i": 1,
            "p": {
                "battery_charge": 1,
                "param179": 0,
                "param180": 0
            }
        }
    },
    {
        "i": 828930,
        "t": "u",
        "d": {
            "prms": {
                "battery_charge": {
                    "v": 0,
                    "ct": 1395374632,
                    "at": 1395374632
                },
                "in": {
                    "v": 0,
                    "ct": 1395374632,
                    "at": 1395374632
                },
                "in1": {
                    "v": 0,
                    "ct": 1395374632,
                    "at": 1395374632
                },
                "in10": 1395374632,
                "in11": 1395374632,
                "in12": 1395374632,
                "in13": 1395374632,
                "in14": 1395374632,
                "in15": 1395374632,
                "in16": 1395374632,
                "in17": 1395374632,
                "in18": 1395374632,
                "in19": 1395374632,
                "in2": 1395374632,
                "in20": 1395374632,
                "in21": 1395374632,
                "in22": 1395374632,
                "in23": 1395374632,
                "in24": 1395374632,
                "in25": 1395374632,
                "in26": 1395374632,
                "in27": 1395374632,
                "in28": 1395374632,
                "in29": 1395374632,
                "in3": 1395374632,
                "in30": 1395374632,
                "in31": 1395374632,
                "in32": 1395374632,
                "in4": 1395374632,
                "in5": 1395374632,
                "in6": 1395374632,
                "in7": 1395374632,
                "in8": 1395374632,
                "in9": 1395374632,
                "param179": 1395374632,
                "param180": 1395374632,
                "param250": {
                    "v": 0,
                    "ct": 1395374632,
                    "at": 1395374632
                },
                "posinfo": {
                    "v": {
                        "y": 24.9639728,
                        "x": 55.202432,
                        "z": 57,
                        "c": 0,
                        "sc": 9
                    },
                    "ct": 1395374632,
                    "at": 1395374632
                },
                "speed": {
                    "v": 0,
                    "ct": 1395374632,
                    "at": 1395374632
                }
            }
        }
    },
    {
        "i": 828930,
        "t": "m",
        "d": {
            "t": 1395374632,
            "f": 3,
            "tp": "ud",
            "pos": {
                "y": 24.9639728,
                "x": 55.202432,
                "z": 57,
                "s": 0,
                "c": 0,
                "sc": 9
            },
            "i": 0,
            "p": {
                "param179": 0,
                "param180": 0,
                "param250": 0,
                "battery_charge": 0
            }
        }
    }
]
}

Please help me how will I get the string and get the data in Asp.net(c#).

1
  • I am getting error during parsing.I am getting Error reading JObject from JsonReader. Path '', line 3, position 1. Commented Mar 21, 2014 at 6:12

5 Answers 5

5

C# is provide WebClient class in System.Net get string using this class like

var json = new WebClient().DownloadString("url");
Sign up to request clarification or add additional context in comments.

Comments

2

get string from url

string Strjson = new WebClient().DownloadString(UrlQuery);

convert json string to Class Object

 ClsObject = (ClsObject) Newtonsoft.Json.JsonConvert.DeserializeObject(Strjson);

or

ClsObject = Newtonsoft.Json.JsonConvert.DeserializeObject(Strjson,ClsObject);

Needs to add the Newtonsoft library to your project

Download Nuget

Comments

1

You can use JavaScript Serializer for this.

See following question answer. Parsing JSON using Json.net

3 Comments

var request = (HttpWebRequest)WebRequest.Create("url"); var response = (HttpWebResponse)request.GetResponse(); var rawJson = new StreamReader(response.GetResponseStream()).ReadToEnd(); var json = JObject.Parse(rawJson);// I am getting error during parsing.
Error reading JObject from JsonReader. Path '', line 3, position 1.
There is some problem with JSON you are creating.
1

text from url can be read using WebClient. This result can be changed to object notation using javascriptSerializer.

3 Comments

I tried the same but json is coming null.I tried the following code. var request = (HttpWebRequest)WebRequest.Create("reportguru.webdenza.com/vdetect-pro-2/api.php?q={\"svc\":\"avl_evts\",\"app\":'" + p_type + "',\"sid\":'" + sid + "'}"); var response = (HttpWebResponse)request.GetResponse(); var json = ExtractJsonResponse(response);
I have two urls.In the first url the string is coming.In 2nd one which I mentioned it is not working.
Then its the problem with JSON you are having.
1

You need to break the task down into steps,.

First get the URL in string format

string url = HttpContext.Current.Request.Url.AbsoluteUri;

Then you need to pull the JSON formatted data and place it into a file (save)

File.WriteAllText(@"c:\url.json", url);

You might have to serialize it using the Newtonsoft JSON.Net framework. But, I believe that's the jist of it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.